cadena y error: new BigNumber() no es un número

Estoy tratando de generar un hash de un archivo y enviarlo a un contrato. pero me sale un error

Error: nuevo BigNumber() no es un número: a8fac6cf98e6f5e9a76ae1f8064e505b(…)

Aquí está mi código de contrato:

function sendHash(address student_id, string hash_value) returns(bool sufficient) 
{ 
    student_hashes[student_id] = hash_value;        
    return true; 
}

Aquí está mi código javascript

function sendHash() {
  getAddresses();
  var meta = MetaCoin.deployed();

  var address = document.getElementById("studentId").value;
  var hash = (document.getElementById("hash").value);
  setStatus("Initiating transaction... (please wait)");

  meta.sendHash(account, hash).then(function() {
    setStatus("Transaction complete!");
  }).catch(function(e) {
    console.log(e);
    setStatus("Error sending contract; see log.");
  });

Estoy usando el tipo de datos 'cadena' en el contrato, pero el error dice que no es un número. Lo he intentado de diferentes maneras, pero no puedo solucionar esto. ¡Cualquier ayuda sería muy apreciada!

Hola, ¿Puedes decirme más sobre la declaración de la variable de mapeo student_hashes? ¿Estás usando mapping(address => string) o mapping(address => uint) ?
Hola @gjeanmart estoy usandomapping (address => string) student_hashes;
Normalmente desea almacenar hashes en bytes32 ya que la longitud es fija y tratar con cadenas de longitud variable en Solidity puede ser un PITA.

Respuestas (1)

Lo hice funcionar. No reproduje su problema "Error: new BigNumber () no es un número:" Entonces, en primer lugar, recomendaría volver a implementar usando

truffle migrate --reset

Luego, debajo de un código de trabajo:

Contrato

pragma solidity ^0.4.4;
contract MetaCoin{
    mapping (address => string) student_hashes;
    function sendHash(address student_id, string hash_value) returns(bool sufficient)  { 
        student_hashes[student_id] = hash_value;        
        return true; 
    }
    function getHash(address student_id) constant returns(string hash)  {       
        return student_hashes[student_id]; 
    }
}

HTML

<!DOCTYPE html>
<html>
<head>
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
  <link href="./app.css" rel='stylesheet' type='text/css'>
  <script src="./app.js"></script>
</head>
<body>
  <h1>Issue</h1>

  <br><label for="address">Address:</label><input type="text" id="studentId"></input>
  <h3>Last hash: <span class="black"><span id="lastHash"></span></span></h3>
  <button id="send" onclick="getHash()">get hash</button>

  <br>
  <h1>Send</h1>
  <br><label for="hash">Hash:</label><input type="text" id="hash"></input>
  <br><br><button id="send" onclick="sendHash()">Send hash</button>
  <br><br>
  <span id="status"></span>
</body>
</html>

JavaScript

var accounts;
var account;

function setStatus(message) {
  var status = document.getElementById("status");
  status.innerHTML = message;
};
function getHash() {
  var c = MetaCoin.deployed();

  var address = document.getElementById("studentId").value;

  c.getHash.call(address).then(function(value) {
    var h_element = document.getElementById("lastHash");
    h_element.innerHTML = value.valueOf();
  }).catch(function(e) {
    console.log(e);
    setStatus("Error getting Hash; see log.");
  });
};

function sendHash() {
  var c = MetaCoin.deployed();

  var address = document.getElementById("studentId").value;
  var hash = (document.getElementById("hash").value);

  setStatus("Initiating transaction... (please wait)");

  c.sendHash(address, hash).then(function() {
    setStatus("Transaction complete!");
    getHash()
  }).catch(function(e) {
    console.log(e);
    setStatus("Error sending hash; see log.");
  });
};

window.onload = function() {
  web3.eth.getAccounts(function(err, accs) {
    if (err != null) {
      alert("There was an error fetching your accounts.");
      return;
    }

    if (accs.length == 0) {
      alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
      return;
    }

    accounts = accs;
    account = accounts[0];
  });
}

Solo una observación: - Cuando envíe una transacción, no olvide agregar al menos {cuenta: %dirección del remitente%}