How can I decode metamask's swap input data?

I am using the python web3/etherscan api and I am not able to decode the input data from the metamask swaps.

I read that metamask uses the erc20 standard, so I used this as abi: https://ethereumdev.io/abi-for-erc20-contract-on-ethereum/ (I do this because I could not get the abi from the contract with web3.)


metamask_router =  web3.toChecksumAddress('0x881d40237659c251811cec9c364ef91dc08d300c')

metamask_contract = web3.eth.contract(address= metamask_router, abi=erc20_abi)

decoded_input = metamask_contract.decode_function_input(transaction['input'])

(The transaction is taken from) transaction = eth.get_proxy_transaction_by_hash(txhash)

I get:

ValueError: Could not find any function with matching select

Actually what I just need to know if the swap is a sell or a buy, but I can't find the way.

1 Answer 1


MetaMask swap service is not open source. You cannot know, without reverse engineering, how to decode inputs and what inputs MetaMask swap service supports.

  • 1
    I see. Thanks for your answer. But does this mean that for a given transfer it is not possible to know if that is a buy or a sell? Etherscan at least does show this information and other plotting services as well so they must have a way of determining the type of the transactions.
    – Jorge
    Commented Dec 7, 2021 at 12:25
  • You can see the underlying ERC-20 token transfers that are independent of MetaMask swap service. So based on the tokens transferred in and out you can deduct what was the price. However, this needs to be done based on event logs from the transaction receipt, not from transaction input. Commented Dec 7, 2021 at 12:27
  • I haven't taken a look at the logs yet, but sounds great. Thanks
    – Jorge
    Commented Dec 7, 2021 at 12:56
  • have you been able to do it? I still cannot find the ABI code Commented Dec 25, 2021 at 18:29
  • If you cannot find ABI code you can open a support ticket on MetaMask support. It is closed source product, not a community supported project and asking any help here is not productive. Commented Dec 25, 2021 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.