Fail with error 'ERC20: transfer amount exceeds balance'

Facing transfer amount exceeds balance when I call method transferFrom

I am using HDwallet provider to sign my transactions

I am using ERC20 by openzeppelin itself while creating the contract

What I want to achieve is basically send tokens from account_2 to account_3 and make account_1 that is the master account holding all the tokens to pay for gas/mining fees. Is that possible? I am new to solidity and smart contracts (blockchain in general) thanks for understanding.

const init = async() => {

try{

await contract.methods.approve(account_address_2,100)

.send({from:account_address_1,gas:10499964})

.on('receipt',async function(data){

    console.log(data.events.Approval.returnValues);

    try{

        await contract.methods.allowance(account_address_1,account_address_2)

        .call().then(async function(data){

            console.log(data);

            try{

                await contract.methods.transferFrom(account_address_2,account_address_3,10)

                .send({from:account_address_1,gas:10499964}).then(function(data){

                    console.log(data);

                })

            }

            catch(err){

                console.log(err);

            }

        })

    }

    catch(err){

        console.log(err);

    }

    });

}

catch(err){

    console.log(err);

}

}

init();

Hi, welcome! :wave:

I am not sure what do you want to do exactly.
There are three accounts: from:account_address_1, from:account_address_2, from:account_address_3, so I assume that you want to transfer token from from:account_address_1 to from:account_address_3, so in this case, the right step should be

  • contract.methods.approve(account_address_2,100).send({from:account_address_1});
  • contract.methods.transferFrom(account_address_1,account_address_3,10).send({from:account_address_2}
1 Like

Hi @Skyge , thanks for the quick reply.
What I want to achieve is basically send tokens from account_2 to account_3 and make account_1 that is the master account holding all the tokens to pay for gas/mining fees. Is that possible? I am new to solidity and smart contracts (blockchain in general) thanks for understanding.

BTW account 2 already has 1000 tokens

Maybe account1 can pay for the mining fee, but for gas fee, in your case, the caller will pay for the gas fee. If you want the account1 to pay for the gas fee, maybe you can have a look at this pattern:
Gas Station Network (GSN) - OpenZeppelin Docs

1 Like

In the above example, account 2 is paying for the gas fees

Will this flow work for transferring token from account 2 to account 3 while account 1 paying for the gas price?

  • contract.methods.approve(account_address_1,100).send({from:account_address_2});
  • contract.methods.transferFrom(account_address_2,account_address_3,10).send({from:account_address_1}

@Skyge @abcoathup Is there a way for account_1 to pay for the gas fees for both approve and transferNow method?