简体   繁体   中英

How to Add a Function to an Already Deployed Smart Contract

I have already deployed a contract on Binance Smart Chain. I now would like to add time lock functionality to this contract to lock some of the tokens for a time period. I know that smart contracts are immutable so there is no way to change the already deployed contract. My question is that: Can I deploy a new contract that only has the time lock function that interacts with my already deployed contract and lock some tokens of the already deployed contract? In a nutshell, what I want to do is to add a new function to an already deployed contract with a new contract. Is this possible? I think it should, because otherwise there won't be any ways to add new functionalities to a deployed contract but I couldn't find any tutorials on that. If there is a way, can you guys point me in the right direction?

Thank you very much.

A usual way to add functionality to a contract is using the upgradable proxy pattern. OpenZeppelin has a very good article that explains this pattern.

In a nutshell: Your user-facing contract does not have any functionality except for a proxy to some implementation, and a function to change the proxy settings from an authorized address. When you need to upgrade, you just deploy the newer implementation to a different address and reflect the new address in the proxy. Because of how delegatecall works, it uses storage of your proxy contract. The values that you have stored, stay the same when you start using new implementation contract.


Can I deploy a new contract that only has the time lock function that interacts with my already deployed contract and lock some tokens of the already deployed contract?

This wouldn't work if you tried to lock existing tokens. The original contract would have no way to call the new contract to check whether it's allowed to transfer the tokens - or whether they're locked.

But if you have a mint feature in the original contract, you could mint new tokens that would belong to the lock contract. The lock contract would allow some authorized users to spend the tokens it owns - only after some time passes (ie timelock).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM