I'm making a mobile wallet to send and receive ERC20 tokens, I finished with the code to Send and Receive, but I don't know what to do if a Token Contract Address changes, what happen if somebody have BAT (for example) and they change de address, do I need to do something? thanks.
ERC-20 – Understanding Token Contract Address Changes
erc-20
Related Solutions
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!
You do not need to set up a BAT specific wallet. The key to a wallet is its ability to sign transactions in the ethereum database.
You can ruffly think of an ERC20 token as a "bank" that allows people to sign "checks" for, and thus transfer value in, that token.
Maybe this list will help explain.
- The etherum network can be thought of as a database.
- The private key owner and only the private key owner of a wallet can sign transactions for the wallets public address.
- Transactions are the only way to update the database.
- The most basic transaction is to send ether; a feature that is so fundamental to the database that you can think of the ether being stored "in the wallet."
- An ethereum contract is a set of rules that specifies how the database can be updated.
- ERC20 is a type of contract that follows a convention. Think about it like bank checks, they don't all look the same (some have pictures of flowers on them, some landmarks, some just lines), they don't all send the same kind of money, some send USD, some send CAD, Euros etc... but all have the name, value, account number, routing number etc.. in the same exact place. If you can read one check you can read them all no matter what currency. And most importantly they are not worth anything unless they are signed (Just like the signed transaction in etherum).
Thinking about it this way, you can think of each ERC20 token as a bank that allows for the transfer of a certain currency.
The bank doesn't actually store physical currency some where it just stores a number which denotes the total amount of currency it controls. In a bank that number is made valid by a central authority (e.g. a government) . In ethereum that number is stored and made valid by the database (e.g. on the blockchain).
You can go to the bank with USD and they will update the number of their total USD and the total USD that you have control over (its not like they keep the exact bills you give them to return to you later). That means when they see a check signed by you, as long as you have control of enough of their total USD then they will do the transfer for you.
Or you could trade something (lets say for 100USD) and someone could give you a check for 100USD written on the USD bank. You then take that 100USD signed check to the bank and just like if you transfered USD directly you now have control of 100USD more of that banks total value.
Shapeshift is more like selling something and someone giving you the ability to sign checks for BAT. You are saying "i am going to give you some ETH and in exchange i should be able to sign some BAT checks." Shapeshift then says "brilliant!, who do you want me to write this BAT check out to? You? Your company? Your dog? Oh and if i can't get the tokens where should i send the refund?"
Your wallet doesn't store the token. The ERC20 contract stores your wallet's signature's ability to transfer tokens.
Another alternative to shapeshift is etherdelta. Which might be easier to understand. https://etherdelta.com
Best Answer
A contract cannot change its address. Token contracts are not an exception.
In practice, a token author may issue a new contract. In such a case, it is always a migration from the old contract to the new, so you have two contracts - the old token and the new token.
You could treat those as separate assets because technically that's what they are. Some user assistance at the UI level is not inconceivable. You might, for example, think of your catalogue of known popular tokens (if there is such a thing) with a version-wise awareness. e.g. TOKv1 @ 0x123... and TOKv2 @ 0x456.
When a token author commences with the unfortunate process of migrating users, users themselves are generally required to trade their V1 tokens for V2 - a process that can be orchestrated via a smart contract. You could consider a friendly user-facing UI to help with that but I think it would need to be flexibly configured on your side to deal with case-by-case implementations as there is no standardized interface (that I know of) for such an exchange contract.
Hope it helps.