Loading...
Let's say we need to send 10000 ERC20 coins with 20 decimals, It will go around 10**24. Sending big number values from javascript cause in Precision error and results in errors. Most of the times 10**24 will not be 10 with 24 zeros it's product will always be greater than 10**24.
We will transfer some ERC20, for that we will use decimals() function for getting decimals and transfer() function to transfer ERC20 tokens.
SmartContractABI = "[
...
]";
SmartContractAddress = "Contract Address";
myContract = new web3.eth.Contract(SmartContractABI, SmartContractAddress);
current_address = "Sender Address";
to_address = "Receiver Address";
var input_value = 1000;
decimals = await myContract.methods.decimals().call({ from: `${current_address}` });
var amount = `${input_value}` + '0'.repeat(decimals);
myContract.methods.transfer(to_address, amount).send({ from: `${current_address}` })