Solidity - Add Token Logo

3.1k Views Asked by At

Glad to see blockchain development support on Stack Overflow as resources as very scarce nowadays.

I'm a new kid trying to learn this ecosystem.

How can I add an image logo to a token that I've already created and deployed on remix.ethereum.org?

Should I have done this before deploying it?

Newbie question: Once deployed the same code can never modified?

I'm currently interacting with the token on BSC - seems that all BSC tokens are created as a fork of Solidity and the ETH ERC20 paradigm. (?)

This is my code

pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

contract Foobar is ERC20 {
    constructor(uint256 initialSupply) public ERC20("Foobar", "FOO") {
        _mint(msg.sender, initialSupply);
    }
}
1

There are 1 best solutions below

0
On

Short answer: No, once you deploy a contract to the mainnet, you can't modify nor delete it, it'll be in the blockchain forever (unless you're using a testnet or a private blockchain network to test the contract).

Long answer: Once a contract is deployed, it can never be modified nor deleted, the only thing you can modify is it's storage (variables that the contract uses) by calling it's defined functions, but you can't modify the logic behind it. If you messed up, you'll need to fix your contract, and re-deploy.

Take in mind that heavy tests and thoughtful inspections are advised before you deploy a contract to the mainnet and set an app into production (and even more if you'r contract will handle sensitive values), mainly because even if you screw up and re-deploy, if you had said contract work in production, its extremly difficult to fix.

For example: You make you'r own tiny bank, the contract recives eth, and it stores it a variable a mapping of addresses with a variable that keeps a count of how much eth from the total eth that the contract is holding is for each user.

contract Bank {
    
    // mapping of address with current money value.
    mapping (address user => uint money) balance;

    constructor(){}

    function withdraw(uint memory money) public {
        // Require money parameter is not empty.
        require(money != 0, "Can't withdraw 0 eth");


        // Big issue here, if we send the money, and then update the balance,
        //    the user will be able to withdraw money even if hi's balance turns 
        //    to 0 if he spams the withdraw function before he runs out of money. 
        //    The good way would be the other way around, first update balance, and then send.

        // Check if the user has enough money.
        if (balance[msg.sender].money >= money) {
            // Send money
            address(msg.sender).transfer(money);

            // Update balance.
            balance[msg.sender].money -= money;
        }

    
    }

    ...
}

Now this has a critical issue, if someone withdraws money twice very fast, it skips a check iteration that checks if the user has enough money in it's balance to withdraw.

Now to fix this, you'll need to quickly withdraw all the money that the contract has and it's mapping(address user => uint money) ... mapping data, fix and re-deploy the contract, manually send all the money to the new contract, and also set the previous data that it had, and if that wasn't enough you'll need to change you'r front-end app to connect with the new contract.

I know its a long example, but when you start coding contracts from 0, you have to understand that testing and revising the contract is a must.

Once a contract is deployed, it cannot be modified nor deleted, it's there forever, alteast in the mainned, that's why you use private blockchains such as Ganache, or use a public testnet (Ropsten, Kovan, Rinkeby, Goerli).

Also about the logo, most tokens don't have their "logo" in their contract ( unless you're making a NFT [ ERC721 ] ), yet, if you still want to add a logo that anyone can access from your contract, i'd suggest to make a state variable that holds its value (string mainly).

The value can be a IPFS hash (IPFS is a decentralized file system that allows you to upload files of any kind, it will return a hash once it's uploaded, and you can access you'r file via https://HASHTOKEN.ipfs.infura-ipfs.io/, for example:

https://bafybeibctnxu7zpatp3caj2gevofs2oirdvdyo6yulxk2hfyaewxib3pj4.ipfs.infura-ipfs.io/

soo in you'r case, you can upload the logo there, grab the hash, and store it in you'r contract, then in your frontend app you'll only need to add the hash to the url.

A second way of adding you'r logo would be to turn you'r image into base64 and paste the whole thing into you'r contract, that way you have literally the image in the contract, yet, i don't recommend this last solution since base64 strings can get very large depending on how heavy is the file, and the heavier you'r contract is, the more gas it will use when you deploy it, and more expensive for the users when they try to use it.

Yet, if what you mean is to add a logo on sites such as BscScan, you can find a guide here.