1

Im using truffle and openzeppelin for issuing my ERC20 token. I already can add and buying the token, but still cannot transfer the token to another.

when i console.log the contract, it show me: Contract

and i created front end for transfer

Transfer Front End

but i little bit confuse how to connected it to the contract to be able to transfering token to receiver address.

for now i just created function transfer like this:

transferToken() {
    let web3 = store.getState().web3.web3Instance
    const receiver = this.state.receipt_add
    const token_value = this.state.token_amount

    const token = contract(IYoToken)
      token.setProvider(web3.currentProvider)

    token.deployed().then(inst => {
        inst.transfer({
            to: receiver,
            amount: token_value
        })
    })
}

but its not working, and the error message is: enter image description here

2
  • Where is the contract deployed? What does the transaction result say? Maybe you can post your code? Also please don't use pictures as you can't copy the contract address from the picture (or at least provide the address in copyable format also) Jul 4, 2018 at 5:00
  • im still using private network for now Jul 4, 2018 at 5:15

3 Answers 3

1

To execute a transfer of ERC20 tokens you have to execute the function transfer(address receiver, uint amount) from your token contract.

In javascript it should be something like

token.transfer(receiver, amount, { from: owner })

In your case this should work

transferToken() {
    let web3 = store.getState().web3.web3Instance
    const receiver = this.state.receipt_add
    const token_value = this.state.token_amount

    const token = contract(IYoToken)
    token.setProvider(web3.currentProvider)

    token.deployed().then(inst => {
        return inst.transfer(receiver,   // <----- ERC 20 token
            token_value,
            { from: token_owner })
    })
}
3
  • contract IYoToken is MintableToken { string public name = "IYo Token"; string public symbol = "IYO"; uint8 public decimals = 18; function transfer(address receiver, uint amount);</br> } so in my contract, i add this one? is it correct? Jul 10, 2018 at 3:37
  • i can transfer, but when i transfer my token 500 token to some address, and after that i check my token balance (from 1000 become 999). something still wrong i think Jul 10, 2018 at 3:41
  • You have to put the value in integer units of the decimals. If your tokens has 5 decimals and you want to move 9 tokens then the value to use is 900000.
    – Ismael
    Jul 10, 2018 at 4:48
0

Apparently this.state.token_amount is invalid. It should be a number (integer). And maybe this.state.receipt_add is invalid too.

0

This error could also occur if the token amount is a big number. You need to include the big number library in your source code to resolve this issue. Once the library has been included you need to convert the token amount to a bignumber using the following statement in js

var x =new BigNumber(amount);

Replace the value of token amount in your transaction with x .Then the transaction should execute sussessfully.

1
  • Ouch, this was probably the right answer, but the OP didn't even bother to select an answer or follow up. That is weak sauce. Jul 7, 2021 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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