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

iamsujit
  • 203
  • 4
  • 9

1 Answers1

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.

stevyhacker
  • 328
  • 4
  • 13