In a previous article about Transparent Upgradeable Proxy in solidity, I showed how this pattern has been used in a real NFT project.
In this article, let's focus on how this kind of project can easily and efficiently be deployed on a testnet to ensure it works well before jumping to mainnet.
Why bother with testnets?
Deploying smart contracts on a testnet offers several advantages over skipping this step entirely. Testnets provide a realistic simulation of the Ethereum Mainnet environment, allowing developers to test contract functionality, interactions, and user flows in a live blockchain setting without risking real funds.
This enables thorough end-to-end testing and allows beta testers to evaluate the application under real-world conditions.
In contrast, skipping testnet deployment means missing out on these critical validation steps. Without testing on a testnet, developers risk deploying untested logic to the mainnet, where bugs could lead to irreversible financial losses or security vulnerabilities.
While local development networks are useful for initial testing, they do not fully replicate the behavior of the Ethereum Virtual Machine (EVM) or the dynamics of a live network, making testnet deployment a necessary intermediate step before mainnet release.
You should not skip this kind of deployment for any serious project.
The project
To illustrate, let's focus on the NFT project I've already talked about: Nifty.
This is a complete NFT project thoroughly tested and able to be deployed at will on sepolia, provided you have the necessary API key from etherscan, a node provider for instance alchemy giving you an access to the test network as well as test ethers you can obtain from a faucet such as chainlink.
Tooling used
Developping and deploying a blockchain project has never been so easy with todays's tooling.
Though you've to keep in mind that some configuration is necessary, in this article I'll briefly cover 2 tools I use on an every day basis when I develop blockchain projects.
Foundry
Must have. Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Nideovim
A tool I made.
You can see it as an attempt to provide isolated and deterministic development environments for any kind of project.
It combines the power of several well-known technologies such as Linux, Docker and Neovim that are fuelled by an evergrowing community that get them more and more powerful.
I'll do a dedicated article on nideovim should you be interested (let me know in comments).
Setup before deployments
Let keep things simple.
- Clone the repository:
git clone https://github.com/MetaBarj0/Nifty.git
- Go to the
contractsdirectory:cd contracts
- Ensure the project can be deployed by running tests:
make test- everything should be green
- Edit the
.envconfiguration file to allow deployement on the test network:- set the
MAINNET_URLvariable to a RPC endpoint of your chosing (I use alchemy as a node provider but any other can do) - set the
SEPOLIA_URLvariable using the same way as for theMAINNET_URLvariable. - set the
MAINNET_FORK_BLOCKto a valid block number for instance23739277but any valid block number is ok. You can get a valid block number of the homepage of etherscan - setup the
PRIVATE_KEYvariable using the private key of a wallet containing enough testETHto deploy the contract. (NEVER EVER use a wallet containing other non test token, you should have a test wallet for these kind of purposes) - setup the
ETHERSCAN_API_KEYto an etherscan API key you or your organization own (you can create one for free).
- set the
That's it for tedious configuration steps. The next part is the actual deployment.
Simply deploy
Only one command to rule the deployment:
-
make sepolia_deploy.
It will deploy the entire set of smart contract to sepolia that are:
- The NFT (Nifty contract)
- The crowd sale (Crowdsale contract)
- a pair of proxies (TransparentUpgradeableProxy contract)
- one for Nifty contract
- one for the Crowdsale contract
This step can take few minutes to complete. Once it's successful, you should see something like All (4) contracts were verified!
Etherscan post deploy steps
As I said, 4 contracts have been deployed and 2 of them are proxies. The next things to do is to get the 2 proxies deployed contract addresses and tell to sepolia that those contract are proxies.
Getting the contract addresses
- Go to the broadcast deployment directory:
cd broadcast/SepoliaDeploy.s.sol/11155111 - look into the
run-latest.jsonfile to get addresses of the 2 proxy contracts:- look for these 2 lines in the file :
"contractName": "TransparentUpgradeableProxy" - get the 2 addresses in the field:
contractAddressof the object you found.
- look for these 2 lines in the file :
Setup proxies
- Go to sepolia etherscan
- in the search bar, put one of the 2 addresses you got from
run-latest.jsonfile - go to the
contracttab -
sepolia etherscanshould tell you this contract may be a proxy (and he's right) - then setup this contract as a proxy
- at the right of the
contract source codeline there is amore optionsdropdown, click on it. - click on
is this a proxy? - on the new page click on
verify - once done you'll get notified the address of the implementation contract
- click
saveand go back to the proxy contract page - repeat the same process for the other proxy
- at the right of the
Deployment done
Once those steps are done, in the contract tab you can see 2 new buttons: read as proxy and write as proxy allowing you to interact with the proxy contract as if it were the underlying implementation contract (Nifty or Crowdsale).
Next steps
Now contracts have been deployed on a public test net, you can interact with them freely using any mean (RPC endpoint using a Node provider, Remix IDE, ...)
Play with deployed contracts
As an exercise left to the reader, make few transactions to deployed contracts using Remix.
I let you same addresses of a previous deployment I made here, should you have any issue deploying yourself:
-
Niftyat0x4a6e3713ce9cc0b18de00e195a0d6ab4d09c2175 -
Crowdsaleat0xe51979cea418896991f17e7a432db652094d6271 -
Nifty proxyat0xdb03331289ceae8ceb3ca9d3888c45d24e5b72a4 -
Crowdsale proxyat0xc2c46f98946b5373b489542f07f42e1993020821
Conclusion
I hope this article has been clear enough and is relevant enough to prove you can deploy projects on test nets to ensure things are going well before deploying it to main net.
Let me know about your thoughts in comment.
Thanks
- @christopherkade for it's banner generator
- Brave Leo's AI to have helped me to build arguments chapter regarding why bother about deploying on test net
- contributor to fantastic dev tools I use every day to build.
- all the community for all invaluable resources I consume every day to be able to make something eventually useful
Top comments (0)