简体   繁体   English

web3 错误:BigNumber 错误:“new BigNumber() 不是基数为 16 的数字:”

[英]web3 error: BigNumber Error: "new BigNumber() not a base 16 number: "

I'm trying to make this simple Dapp work where I'm sending the variables nombre and edad to the setInstructor() function and then returned by the getInstructor() function.我试图让这个简单的 Dapp 工作,我将变量 nombre 和 edad 发送到 setInstructor() 函数,然后由 getInstructor() 函数返回。 The problem is that I keep getting BigNumber Error: "new BigNumber() not a base 16 number: . Any thoughts?问题是我不断收到BigNumber Error: "new BigNumber() not a base 16 number: 。有什么想法吗?

Solidity坚固性

pragma solidity ^0.4.25;


contract Contrato {

  string fName;
  uint age;

  function setInstructor (string _fName, uint _age){
      fName = _fName;
      age = _age;

  }

  function getInstructor () public constant returns (string, uint){
      return (fName, age);
  }

}

Web3网络3

var Contrato = web3.eth.contract(ABI);
var Contratito = Contrato.at(Address);

$("#button").click(function(){

    Contratito.setInstructor($("#nombre").val(), $("#edad").val(), function(error,result){if (!error) { console.log("bien") } else { console.error(error)}});

    Contratito.getInstructor(function(error,result){ if (!error) { $("#instructor").html(result[0] + " " + result[1])} else {console.error(error)}});

})

I'd start by converting $("#edad").val() to a number rather than the string most likely returned. 我将从将$("#edad").val()转换为数字而不是最有可能返回的字符串开始。 If that doesn't work I would convert both .val() results to BigNumbers manually with new BigNumber(...) . 如果这样不起作用,我将使用new BigNumber(...)手动将两个.val()结果都转换为BigNumbers。

Let me know where that leaves us in the comments and hopefully we'll get this fixed quickly! 让我知道在评论中留下的内容,希望我们能尽快解决!

I had this problem as well, in order to fix it I had to change the network my MetaMask browser extension was using to the one specified in the javascript code. 我也有这个问题,为了解决它,我不得不将我的MetaMask浏览器扩展所使用的网络更改为javascript代码中指定的网络。 Make sure the contract address is located on the network the MetaMask extension is using. 确保合同地址位于MetaMask扩展正在使用的网络上。 Also you should probably post your Ethereum related questions on the Ethereum stack exchange site to get a quicker response: https://ethereum.stackexchange.com 另外,您可能应该在以太坊堆栈交换站点上发布与以太坊相关的问题,以获得更快的响应: https ://ethereum.stackexchange.com

In my case the problem was related with EVM version being used.就我而言,问题与使用的EVM版本有关。

I've to move from the default one ( bizantium ) to explicitly indicate the homestead version and it worked.我必须从默认的( bizantium )移到明确指出宅基地版本并且它有效。

But attention homestead is the oldest one so I'm not sure of the implications of my choice.但是attention homestead是最古老的,所以我不确定我选择的含义。 I did not try with other versions because it was a contract for test only purposes.我没有尝试使用其他版本,因为它是仅用于测试目的的合同。

The command to compile the contract and indicate the EVM version (example):编译合约并指示EVM版本的命令(示例):

solc --evm-version <VERSION> contract.sol

Reference: https://solidity.readthedocs.io/en/v0.5.3/using-the-compiler.html#setting-the-evm-version-to-target参考: https : //solidity.readthedocs.io/en/v0.5.3/using-the-compiler.html#setting-the-evm-version-to-target

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM