[Ethereum] How do ERC-20 Tokens work

basic-attention-tokenerc-20tokens

I thought I understood ERC-20 tokens. However, I wanted to purchase a small amount of basic attention token (like $5) to learn and experiment with. That's when I realized that I didn't understand them as well as I thought. The confusing part for me is basically in the transfer and storage. Allow me to use BAT as an example.

The Brave browser let's you add funds by sending Ether to your Brave wallet. The address of that wallet is provided in the Brave browser. Let's pretend that I didn't want to use all of the BAT immediately. So, I would want to store the BAT I didn't want to use on a hardware wallet like a Ledger. I'm trying this just to learn how it works. This is where I'm confused.

From my understanding, I don't see a way to send BAT to an address. Once it's in the Brave Wallet, it's there. Even if there was an option to "send" BAT to an address, I don't know what address on the Ledger to send it to. What denotes that a wallet address is a "BAT" wallet address? Does a single Ethereum wallet automatically recognize the token types? Or, does each token need it's own wallet? I've been told that Ledger wallets can hold BAT. Yet, the Ledger app only seems to recognize Ether.

So, does each ERC-20 token need it's own wallet? Or, do you just need one Ethereum wallet and the Ethereum platform recognizes the type of token?
While I've used BAT as an example, I'm trying to understand it in the context of other ERC-20 tokens as well.

Best Answer

There is no difference between a wallet containing BAT and one that does not (aside from the fact that one can send now send BAT tokens, of course). In fact, the BAT tokens are never actually stored in the wallet. The tokens are "stored" in the BAT contract -- and this is true of all ERC-20-compliant tokens. Each ERC-20 contract contains a mapping of wallet addresses to account balances. An ERC-20-aware wallet will know that the ERC-20's software interface has a balanceOf function to examine token balances and some functions for transferring named transfer and transferFrom. You can think of "transfers to a wallet" as more of a "request to the relevant ERC-20 contract to hold tokens in trust on behalf of an owner of a wallet".

Since an account receiving a token doesn't actually receive any tokens (it's some number shifting in the token contract), to see if you have any tokens of a particular type, you need to query the mapping of the appropriate token. Some wallets may automatically check (AKA watch) some common tokens, but a fully-featured Ethereum wallet should be able to interact with any ERC-20 token; it just requires user input to direct its "attention" towards a particular ERC-20 contract. A non-fully-featured Ethereum wallet may not let you interact with the contract, even if you have received the tokens at your wallet address. In that case, you will need to export the private keys for the wallet and import them into a more featured wallet. Don't worry; those tokens aren't lost!

Related Topic