I create my wallet like this
const wallet = ethers.Wallet.createRandom()
I use metamask to send RIF tokens to the public address. I confirm the new balance of the account and it is accurate, the ERC20 transaction worked.
When I try to send some of the RIF token from that wallet, like this:
const connectedWallet = await wallet.connect(provider)
const contract = new ethers.Contract(
process.env.CONTRACT_ADDRESS,
rifContractAbi,
onlineWallet,
)
await contract.transfer(to, tokens)
I get the following error:
error: Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":246,\"error\":{\"code\":-32010,\"message\":\"the sender account doesn't exist\"}}\n", error={"code":-32010}, requestBody="{\"method\":\"eth_sendRawTransaction\",\"params\":[\"0xf8a8808403e252e08290999419f64674d8a5b4e652319f5e239efd3bc969a1fe80b844a9059cbb00000000000000000000000010d158b42bfbf39641896ad8b8fd9cf7078d2f4e0000000000000000000000000000000000000000000000000de0b483f7abe82062a0175a2b6e35c1ff301ff45341bf5a63a3895a63404c78b6644cd2f8dee5b9a030a010fbbd608476a555bccd9f3ccf67ceac46183f1be4a82b14a46bbb78ba312fc9\"],\"id\":246,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://public-node.testnet.rsk.co", code=SERVER_ERROR, version=web/5.7.0)
As soon as I sent some RBTC to that account the transaction works.
Explanation
In order to successfully transfer ERC20 tokens, the EOA performing the transaction will need to satisfy 3 conditions:
Reproduce the problem
If you do the above, and then immediately execute the following:
... you have yet to satisfy conditions (1) and (2) above. Therefore (3) will also be rejected as a result.
Solution
To check if you have satisfied condition (1):
If this value is insufficient, and you're on RSK Testnet, can visit
faucet.rifos.orgto obtain sometRIFtokens.To check if you have satisfied condition (2):
Set the value of
ERC20_TRANSFER_GAS_ESTIMATEby using a gas estimation method, or even hard-coding its value to a safe overestimate (e.g.1e6)If this value is insufficient, and you're on RSK Testnet, can visit
faucet.rsk.coto obtain sometRBTCcryptocurrency.After satisfying the above, and you subsequently execute the following once more:
... the transfer should succeed.