[Ethereum] Invalid number value when deploying contract using truffle? But how to fix it in code is the value or _amount variable ?i cannot figure it out

ethersoliditytruffleweb3js

2_deploy_contracts.js

Replacing 'OraclizeTest'


Error: * Deployment Failed *

"OraclizeTest" — invalid number value (arg="_amount", coderType="uint256", value={"from":"0xb5Fb3E9BB73e742689F1001C519d6763a39A4Bc5","gas":6721975,"value":1000000000000000000}).

at /root/.nvm/versions/node/v9.11.2/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:364:1
at
at process._tickCallback (internal/process/next_tick.js:182:7)
Truffle v5.1.8 (core: 5.1.8)
Node v9.11.2

var OraclizeTest = artifacts.require("./OraclizeTest.sol");

    module.exports = function(deployer, network, accounts) {
      // Deploys the OraclizeTest contract and funds it with 0.5 ETH
      // The contract needs a balance > 0 to communicate with Oraclize
      deployer.deploy(
        OraclizeTest,
        { from: accounts[9], gas:6721975, value: 1000000000000000000 });
    };

contract OraclizeTest is usingOraclize {

    using strings for *;        //strings import requirement
   // string public matchId; 
    uint256 public amount; 

//remove url traces
    address public homeBet;  
    address public awayBet;


    //string public ETHUSD;

    event LogInfo(string description);      //getting from update function
//event LogPriceUpdate(string price);     //waiting for price in callback 
    //then calling update function 
    //event LogUpdate(address indexed _owner, uint indexed _balance);     //getting from constructor 

    // Constructor
    function OraclizeTest (uint _amount) public {      //adding args and not matchid
        amount = _amount;        

    //    emit LogUpdate(owner, address(this).balance); //owner was in original

        // Replace the next line with your version:
        OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);

        oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
        update();
    }

Best Answer

No no no.

The accepted answer above is incorrect, and the fact that you've accepted it means that not many users will even read your question (let alone try to answer it).

The integer value of 1000000000000000000 is indeed larger than Number.MAX_SAFE_INTEGER, and you should therefore use "1000000000000000000" or "1e18". But that's not what the error message tells you, and the suggested solution will therefore not fix that error.

Look at the error:

invalid number value (arg="_amount", coderType="uint256", value={"from":"0xb5Fb3E9BB73e742689F1001C519d6763a39A4Bc5","gas":6721975,"value":1000000000000000000}).

It tells you very explicitly that the function expects a number value (which you can pass as either a native integer Number, a string representing an integer number, a BigNumber object if you're on web3.js v0.x, or a BN object if you're on web3.js v1.x onward), but has received this instead:

{
    "from":"0xb5Fb3E9BB73e742689F1001C519d6763a39A4Bc5",
    "gas":6721975,
    "value":1000000000000000000
}

Looking at the function that you are trying to call:

function OraclizeTest(uint _amount)

And it indeed expects one input parameter of type uint, which you are no passing to it.

The object which you are passing is an additional parameter which web3.js allows you to pass in order to provide the transaction details. This object must be the last parameter passed to any function, and of course, it is not stated explicitly in the contract function itself (but implicitly via msg).

In short, your call to function OraclizeTest is missing the input parameter _amount.

Related Topic