Key-Value store Developer Tutorial
Learn how to use SecretPath on EVM to encrypt payloads.
Overview
SecretPath seamlessly handles encrypted payloads on the EVM, which means EVM developers can use SecretPath to encrypt and decrypt messages cross-chain with little-to-no Rust experience required.
This tutorial explains how to upload your own Key-value store contract on Secret Network, which you can use to encrypt values on the EVM, as well as how to encrypt payloads and transmit them cross-chain. After this tutorial, you will have the tools you need to use SecretPath to encrypt messages on any EVM-compatible chain.
Getting Started
To get started, clone the SecretPath tutorials repository:
Configuring Environment Variables
cd
into encrypted-payloads/evm-contract
Install the dependencies:
Create an env
file and add your:
EVM wallet private key
Infura API endpoint (Sepolia testnet)
See here for a properly configured example env file
Get sepolia tokens from faucet:
This tutorial is for Sepolia testnet, but there are 10+ chains currently configured that are also compatible by simply swapping out the SecretPath gateway address.
Now that your developer environment is properly configured, you're ready to encrypt your first payload with SecretPath!
Upload the Key value store contract on Secret Network
cd
into encrypted-payloads/secret-contract
Compile the Secret Network key value store contract:
cd
into secret-contract/node
Install the dependencies:
Open the upload.js file and review the instantiate message at line 70:
gatewayAddress is the SecretPath gateway contract address for testnet
gatewayHash is the SecretPath gateway contract hash for testnet
gatewayKey is public key used for SecretPath encryption on Secret testnet
These three parameters remain constant and must be passed for every Secret Network contract that implements SecretPath. They can be found here for testnet.
To upload and instantiate the contract, run node upload
:
Upon successful upload, a contractHash
and address
will be returned:
Encrypt a payload
Now that you have your key value store smart contract uploaded on Secret Network, let's use it to store encrypted messages. Most of the ECDH cryptography has been abstracted away so there are only a few values you need to change.
cd
into encrypted-payloads/evm-contract:
Open encrypt.js
in evm-contract/scripts and navigate to lines 43-49.
Update the routing_contract
and routing_code_hash
to the contract address and codehash
of the Secret Network smart contract that you instantiated:
publicClientAddress
is the gateway contract address for Sepolia, which is found in Secret's gateway contract docs here.
Next, update lines 73-77 with the EVM wallet address associated with the private key in your env file (myAddress)
, a key (any string
of your choosing), a value, (any string
of your choosing), and a viewing_key (any string
of your choosing).
value
is the the data that you want to encrypt, key
and viewing_key
are parameters you pass to encrypt the value.
Next, you are going to set the handle
variable to call the store_value
function inside of the Secret contract that you instantiated earlier. You do this with line 80, which corresponds to the store_value
function in the Secret contract:
Once you have decided upon these parameters, simply run encrypt.js:
Upon successful encryption, your payload hash will be returned:
Congrats, you have encrypted your first cross-chain payload with SecretPath!
Decrypt your payload
To decrypt your encrypted payload, cd
into secret-contract/node
Open decrypt.js and update lines 8-9 with your key
and viewing-key:
Then run node decrypt:
Your decrypted payload will be returned:
Congrats! You have now used SecretPath to encrypt and decrypt cross-chain payloads! 🔥
Summary
SecretPath is a powerful addition to Secret Network’s cross-chain messaging capabilities. Along with IBC and Axelar GMP, and eventually to be joined by additional bridging technologies like Wormhole and Union, it enables groundbreaking new use-cases for Web3 applications by providing access to confidential computation. This facilitates novel applications such as private voting for DAOs, secure random number generation, confidential data access control via NFTs, encrypted DeFi order books, sealed-bid auctions, and storing encrypted data.
We also encourage developers to check out our grants program to get funding for building with SecretPath, and to join our Discord and Telegram to get involved with our community. You can also contact our team directly if you have any questions about building on Secret.
Last updated