Solidity

錯誤:new BigNumber() 不是 16 進制數:嘗試從映射中檢索字元串時

  • March 27, 2018

我創建了一個相當簡單的智能合約,已部署到 rinkeby 測試網。你可以看到下面的程式碼:

pragma solidity ^0.4.18;

contract KVStore {

mapping(address => mapping(string => string)) store;
uint MAX_STR_LENGTH = 1000;

function get(address _acct, string _key) public view returns(string) {
   return store[_acct][_key];
}
function set(string _key, string _value) public {
  if (bytes(_value).length <= MAX_STR_LENGTH) {
    store[msg.sender][_key] = _value;
  }
}

}

我正在使用 geth 呼叫 set 函式,然後呼叫 get 函式。但是,當我呼叫 kvstore.get(address, key) 時,出現以下錯誤:

Error: new BigNumber() not a base 16 number: 

我不確定發生了什麼或如何解決。set 函式工作正常並寫入 rinkeby 鏈。

我首先執行這個:

geth --verbosity 0 console --rinkeby

然後

var kvstoreContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"_key","type":"string"},{"name":"_value","type":"string"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_acct","type":"address"},{"name":"_key","type":"string"}],"name":"get","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]).at("0xf8daca377691c8f52b07ef77dfc0e7ca287622c5");

然後

kvstoreContract.set("fly","star",{from:eth.accounts[1]});

哪個工作正常並將交易發送到契約地址。

當我嘗試做

kvstoreContract.get(eth.accounts[1],"fly");

我收到 bigNumber 錯誤。知道為什麼嗎?我真的很感激幫助。

終於想通了。一直在傳遞錯誤的契約地址……那會得到你的!

引用自:https://ethereum.stackexchange.com/questions/43818