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:
Best Answer
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