Search code examples
blockchainsolidityerc20bep20

After compiling my erc20 token, can I modify any function?


I am getting into a Token project. Can I append more functions to the token and more smartcontract after compiling the token to the BSC, or is there nothing else to be done at that point?


Solution

  • Solidity source code is compiled to the EVM-compatible bytecode. Then you can deploy the bytecode to the actual live network.

    After you compile the code (using solc, short for the Solidity compiler), you can update it and recompile for as many times as you want.


    But, I'm guessing you wanted to ask if you can update the code after you've deployed it to the network.

    The simple answer is: No. Bytecode is immutable, and once you've deployed it, there's no way to change it.

    Having said that, ... you can make use of the Proxy pattern, where you don't actually change the bytecode, just a pointer (value in storage) to an address that holds the contract implementation. This allows you to deploy a new version of your contract to a new implementation address (in the background), while users still interact with the original proxy address (in the front). See this page by OpenZeppelin for more details, code examples, and diagrams of how this works in more depth.

    Advanced topic: Thanks to the combination of selfdestruct and create2 EVM opcodes, it's also possible to destroy the contract and redeploy it with new constructor params. This article sums it up neatly.