cartesi / cli

Cartesi CLI tool
Apache License 2.0
3 stars 3 forks source link

Set allowance during ERC-20 deposit #22

Open tuler opened 2 months ago

tuler commented 2 months ago

📚 Context

The ERC-20 contract requires to set an allowance before depositing tokens into the ERC20Portal contract. cartesi send erc20 does not handle allowance, so it often fails like so:

➜  cartesi-app cartesi send
? Select send sub-command Send ERC-20 deposit to the application.
? Chain Foundry
? RPC URL http://127.0.0.1:8545
? Wallet Mnemonic
? Mnemonic test test test test test test test test test test test junk
? Account 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 9999.964983134519619707 ETH
? Application address 0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e
? Token address 0x92C6bcA388E99d6B304f1Af3c3Cd749Ff0b591e2
? Amount 1
    ContractFunctionExecutionError: The contract function "depositERC20Tokens" reverted with the following signature:
    0xfb8f41b2

    Unable to decode signature "0xfb8f41b2" as it was not found on the provided ABI.
    Make sure you are using the correct ABI and that the error exists on it.
    You can look up the decoded signature here: https://openchain.xyz/signatures?query=0xfb8f41b2.

    Contract Call:
      address:   0x9C21AEb2093C32DDbC53eEF24B873BDCd1aDa1DB
      function:  depositERC20Tokens(address _token, address _dapp, uint256 _amount, bytes _execLayerData)
      args:                        (0x92C6bcA388E99d6B304f1Af3c3Cd749Ff0b591e2, 0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e, 1000000000000000000, 0x)
      sender:    0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

    Docs: https://viem.sh/docs/contract/decodeErrorResult
    Version: viem@2.9.31

✔️ Solution

cartesi send erc20 could also take care of the allowance transaction.

🎯 Definition of Done