0

i'm trying to transfer a value of 1 of my erc20 token to my contract. In my front end I am using:

tokenContract.methods.approve(contract_addr, 1).send({from: accounts[0]});

In my smart contract I am using:

tokenContract.transferFrom(msg.sender, address(this), 1);

This all works fine, in as much as I get a successful token transfer. The issue is what is being received by the contract is not 1 token, but 0.000000000000000001. My question is what conversions do I have to do to ensure 1 is sent, and where do I do the conversion? Front end, smart contract or both? Thanks so much for any help.

2
  • those erc20 contract is being developed by you? Sep 16 at 22:42
  • @AlbertoSinigaglia its my token yes but it inherits everything from erc20, i didnt write any of its functions
    – Oblivion
    Sep 17 at 6:29
1

So turns out both the front end and smart contract represent tokens in wei, so 1 token is 0.000000000000000001. In my front end I changed the 1 to web3.utils.toWei("1", 'ether'); and in my smart contract did 1 * 10 ** 18. This worked perfectly.

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.