-1

I am building a token smart contract using truffle and ganache. i was testing the transfer function. Code is in the image below

TOKEN.js

In my token.sol file i created a function name transfer

function transfer(address _to, uint _value) public {

When i ran the test using the command 'truffle test'

It threw this error "invalid address (arg="", coderType="address", value=[0])"

Please how do i fix this. I think its from the new truffle compiler because i also ran into an error when trying to fetch the accounts in my ganache using the command web3.eth.accounts i learnt it has been depricated.

Iammrjude1
  • 31
  • 1
  • 8
  • Usually if you run into this issue you aren't actually passing a value into the function - double check that you've set an address or a variable to hold an address and that you're definitely passing it into the function - the error message you're getting is basically saying that the argument is empty. – jacobedawson Feb 07 '21 at 18:28

1 Answers1

-1

I had the same problem a few days ago and I solved at this

await token1.transfer(accountAddress, quantTokens1ToSend)

your transfer function requires 2 parameters the _to and the value, you don't need to put the from like you putted, because the from address will be the tokenInstance contract address, named as msg.sender in solidity, and I recommend also to put the await keyword before the tokenInstance.transfer because it's a promise and you must wait it's result before return(it's not a rule but I recommend)

And the recommend way to call a smart contract in this case could be:

await tokenInstance.transfer(accounts[0], '250000')