0

I need to determine an expiry date for a contract a for this I use the foloowing code as the constructor of the contract :

constructor(address _recipient, uint256 duration)
        public
        payable
    {
        sender = msg.sender;
        recipient = _recipient;
        expiration = now + duration; // Here we determine the expiry date.
    }

However when I want to determine this expiry date for one day (60 * 60 * 24 = 86400 seconds) at the time of deploying this contract using the following web3.js commands :

const thisContract = new web3.eth.Contract(abi);
thisContract.deploy({  
        data: bytecode,
        arguments: [ "0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2", [86400/*here is duration*/] ]
    }).send({
       from: "0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163",
       gas: 5000000 ,
       gasPrice: '3000000000',
       value: 5000 
    },
    function(error, transactionHash) {
        console.log(error);
        console.log(transactionHash);
        console.log('function exec');
    }).then(function(newContractInstance) {
    console.log('Contract Instance:' + newContractInstance.options.address);
});

Then, I receive the following error concerning converting the Integer to Big Number :

Error: [number-to-bn] while converting number [3600] to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported. Given value: "3600"

And here is the screen shot:

enter image description here

1

You entered an array of one number instead of the number itself.

Change

arguments: [ "0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2", [86400/*here is duration*/] ]

to

arguments: [ "0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2", 86400]

and it should work

1

The error message says:

[number-to-bn] while converting number [3600] to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported. Given value: "3600"

This means that instead of [3600] you should pass either one of the following:

  • 3600
  • "0xE10"
  • web3.utils.toBN(3600)
  • new BigNumber(3600)

For the last option, be sure to install BigNumber v7.0.0 or later, for compatibility with Web3 v1.x (otherwise you might get other runtime errors at a later point).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.