1

I have tried this solution and it worked but only if I use privateKey of the wallet which I used to create custom tokens but what if I want to send from B wallet to C wallet and when I am trying it, the transaction is happening but it's failing.

Failed transaction

var contract = new ethers.Contract(contractAddress, abi, wallet);

var numberOfTokens = ethers.utils.parseUnits('10.0',numberOfDecimals);
var options = { gasLimit: 1500000, gasPrice: ethers.utils.parseUnits('1.0', 'gwei') };

contract.transferFrom(fromAddress, targetAddress,numberOfTokens,options).then(function (tx) { console.log(tx); });

thanks

2
  • 2
    Has the token owner added an approve for the tokens? They can't be transferred without his consent. – Lauri Peltonen Mar 20 '19 at 13:08
  • 1
    i am the owner but how to approve the transfer? – iamsujit Mar 20 '19 at 17:17
2

For this to work, you have to call an approve function of the ERC20 token smart contract that you want to transfer. You have to pass the amount that you want to transfer and the spender address to the approve function. Only then you will be able to make the actual transfer.

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.