简体   繁体   中英

Getting new BigNumber() error when calling a function in solidity using truffle. How do I fix the error?

I get this error when I try to call my solidity function using truffle.

在此处输入图片说明

My solidity code is as :

pragma solidity ^0.4.14;

contract SimpleDemo {
    function returnNumber () public view returns (uint) {
        return 500;
    }
}

The way I'm calling returnNumber() is by :

this.state.web3.eth.getAccounts((error, accounts) => {
    simpleDemo.deployed().then((instance) => {
        simpleDemoInstance = instance
        // Below line runs with the error ...
        return simpleDemoInstance.returnNumber.call()
    }).then((result) => {
        console.log(result)
    })
})

Also, this solution did not help at all. Hence, I asked separately.

It should be:

simpleDemoInstance.methods.returnNumber().call({ from: accounts[0] });

if it is a function that takes gas(assuming you want to send from metamask).

If it is not a payable function you use:

simpleDemoInstance.methods.returnNumber().call()

Also use es6. Trying to write this stuff without async await is terrible IMO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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