I am having problem using bignumber.js with web3:
const sender = '0xss';
const recipient = '0xxx';
const amount = 1000; // have to use Bignumber for more than 1000
const decimals = 18;
const amountHex = web3.utils.toHex(new BigNumber(`${amount}e+${decimals}`));
const count = await web3.eth.getTransactionCount(sender);
const data = contract.methods.transfer(recipient, amountHex).encodeABI();
const estimateGas = await web3.eth.estimateGas({
from: sender,
nonce: '0x' + count.toString(16),
to: '0xff',
data
});
I get error at estimateGas :
Error: Returned error: The execution failed due to an exception.
contract.methods.transfer
would fail if you called it with the given parameters.transfer
function looks like and what it could fail for, because you haven't bothered to post the code of this function!${amount}e${decimals}
)); then it work.${amount}e${decimals}
trick! Where did you learn that?