5

When I use web3js and Truffle, I cannot send tokens to another wallet without the Token Contract ABI. But Metamask only requires the token contract address to recognize and send the ERC20 tokens. How do they do it?

1

3 Answers 3

2

Metamask uses internally a simple ERC20 compatible ABI, defined on the basis of the standard. As you may know, any

function transfer(address, uint)

is described by the same ABI element for any possible contract existing incorporating it, being it (the ABI element) nothing more that an hashed description of the call name and of the parameters type.

So if you suppose that the contract to connect with has, at least, one transfer, one balanceOf, one approve, one transferFrom and so on, you can write down a usable ABI that shall give you access to those functions in the contract without hassle.

Of course you shall not be able to access any other function existing in the specific contract that you did not described in advance using that approach.

1
  • You are welcome!
    – Rick Park
    Commented Dec 24, 2018 at 3:47
5

ERC20 is an interface by definition. MetaMask has explicit support for this type of contract. It does not support contracts with arbitrary interfaces.

Hope it helps.

0
2

To transfer the token you need an ABI for interface defined in the standard. Metamask uses human-standard-token-abi npm package to access the token ABI. You can see its inclusion in metamask here.

0

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.