Deploying Smart Contracts with Foundry
This is a guide to creating and deploying smart contracts with Foundry on the Syscoin NEVM.
NOTE: Syscoin is designed to be a settlement layer for zkRollups and other L2s/execution layers, as such it has a 2.5 minute block time for the optimal settlement security, it is advised to create dApps using zkRollups rather than using the Syscoin blockchain itself for executing smart contracts. You can find zkRollup resources here.
info
Syscoin's public NEVM test network is the Syscoin NEVM Testnet, sometimes labeled “Tanenbaum”. We'll stick with the Syscoin NEVM naming for the rest of this guide.
This guide assumes that you have already:
- Installed Foundry on your system
- Prepared a Syscoin NEVM wallet with a funded deployment account
1. Create a new project#
Make a new directory where you wish to create your project then cd into it and run the command below:
2. Create a new contract#
Create a new file in the src directory called HelloNEVM.sol.
Paste the following code into the HelloNEVM.sol file.
note
The example uses the MIT SPDX identifier for permissive reuse. Adjust the license string to align with your project’s requirements before deploying to production.
3. Configure the network used by Foundry#
Foundry reads configuration from environment variables. Add the values to a .env file in your project root.
When you want to deploy, load the variables into your shell:
If you need to target mainnet, run export ETH_RPC_URL=$SYSCOIN_MAINNET_RPC_URL instead.
Note: Keep the 0x prefix on the key and ensure .env is ignored by git so credentials don’t leak.
4. Deploy the contract#
Once you have configured the environment variables, you can deploy the contract.
You will then receive something similar to the following output showing that the contracts have been successfully deployed.
Congratulations! Your contracts have been deployed and you can see the contract's address in the output, which is worth saving if you wish to interact with it at a later date.
5. Verify the Contract#
After deploying, you should verify your contract on the block explorer. Foundry can do this using the forge verify-contract command. Since Syscoin uses a Blockscout explorer, you need to provide the API URL.
To verify the HelloNEVM contract, run the following command, replacing YOUR_CONTRACT_ADDRESS with the address from the deployment step.
For the Syscoin NEVM Testnet:
You can view your verified contract on the testnet explorer: https://explorer.tanenbaum.io
For Syscoin Mainnet:
You can view your verified contract on the mainnet explorer: https://explorer.syscoin.org
This command tells Foundry to use the specified explorer's verification endpoint. No API key is required.
tip
Prefer scripted deployments? Check out forge script and the --broadcast flag to codify your deployment steps before shipping to production.