EVM Developer Tutorial — Deploy Your First Secret Contract
In this tutorial for EVM developers, you will learn the basics of working with Secret contracts
Overview
If you are an EVM developer who is new to Secret Network smart contracts, this tutorial is for you. You will learn how to:
- Connect your Metamask wallet to a Secret Network wallet address
- Fund your Secret wallet
- Upload + Instantiate your first Secret contract
- Execute and Query a Secret contract
This tutorial will give you the tools you need to work with the entirety of the Secret Network EVM developer toolkit. Let’s dive in! 🏊
Connecting Metamask to Secret Network
- Connect your Metamask wallet here to receive your Secret testnet wallet address
- Fund your Secret testnet wallet address with the testnet faucet
Now you have a Secret Testnet wallet address that you can use to sign transactions with your Metamask wallet! 🤯
Setting up your Developer Environment
First, configure your developer environment by installing rust.
Once you have installed rust, add the WASM build target:
rustup target add wasm32-unknown-unknown
Fork the EVM Getting Started repository:
Git clone the EVM Getting Started repository:
Git clone https://github.com/<your-github-username>/workshops.git
Uploading a Secret Contract
Open the repository in your code editor and cd into evm-getting-started/secret-contract-example:
cd evm-getting-started/secret-contract-example
The Secret Network smart contract is a simple counter contract that can:
- increment the starting count by 1
- reset the current count
- query the current count
Let’s compile it and upload it to Secret Network testnet!
Compile the contract
RUSTFLAGS=’-C link-arg=-s’ cargo build — release — target wasm32-unknown-unknown
After the contract compiles successfully, you will see a contract.wasm.gz file in ./secret-contract-example.
Upload the contract
Open a new terminal window and cd into evm-getting-started/node:
cd evm-getting-started/node
Install the dependencies:
npm i
Upload + Instantiate the contract:
node deploy
Upon successful instantiation, a contract address will be returned:
codeId: 4845
Contract hash: 3bf70d2194564884515d292e720119a3bdee52fdc5bdf865ab36323401442bd8
contract address: secret1ew8yaggu0yyqtyjqx3yp4hjezf5vryxwj6p4tt
Executing a Secret Contract
Open a new terminal window and cd into ./metamask-example:
cd evm-getting-started/metamask-example
Install the dependencies:
npm i
At line 9 in App.js, update the contractAddress and codeHash to your contractAddress and CodeHash:
Then start the application:
npm run start
Now when you connect your wallet, you should be able to increment the count! 🎉
Push your changes:
Git push origin <your-branch-name>
Summary
By following this guide, you’re now equipped to take your Ethereum development skills into the world of Secret Network. You’ve learned how to connect your Metamask wallet to Secret Network, making it possible for you to interact with a confidential blockchain. You’ve also added funds to your Secret Network wallet, uploaded and set up your first smart contract, and discovered how to execute and check on your smart contracts. With these steps completed, you’re ready to dive into building decentralized applications that prioritize user privacy on the EVM.