Learn how to mint cross-chain privacy-preserving NFTs with SecretPath
SecretPath enables EVM developers to use Secret Network as a Confidential Computation Layer (CCL) for all EVM-compatible chains.
In this developer tutorial, you will learn how to use SecretPath to enable cross-chain NFTs on the EVM. You will mint an NFT on Sepolia testnet that uses a sister contract on Secret Network to store private metadata, which can only be accessed by a private password stored in the Secret Contract. And to spice things up, we will generate the NFT image with OpenAI 🔥.
Generate an AI image with OpenAI
Pin the newly generated image with Pinata to create the token URI
Mint the NFT on Sepolia with your token URI
Send the confidential metadata to your Secret Contract with SecretPath
See Cross-Chain NFT demo here.
Git clone the repository:
cd into secretpath-nft/secret-contract
Compile the contract:
If you are on a Mac and run into compilation error:
error occurred: Command “clang”
Make sure you have the latest version of Xcode installed and then update your clang path by running the following in your terminal:
cargo clean
AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang cargo build --release --target wasm32-unknown-unknown
See here for instructions on updating your clang path.
Once the contract compiles successfully, install the dependencies to upload it to testnet:
Create an .env file and add your Secret wallet mnemonic:
Upload the contract:
Upon successful upload, your contract address will be returned:
Before we upload the EVM contract which mints the NFT, let's examine what the Secret Network sister contract does.
Navigate to the state.rs
file to the ConfidentialMetadata
struct:
This is the confidential metadata that you will be storing in the Secret Network smart contract for each NFT that you mint on the EVM. There is an owner
, token_id
, uri
, private_metdata
, and password
, all of which will be associated with each NFT you mint.
Now open contract.rs
and navigate to the execute_store_confidential_metadata
function.
Here we have a keymap
called CONFIDENTIAL_METADATA
, which maps the token id
of your EVM NFT to a ConfidentialMetadata
struct. So for every NFT you mint on EVM, it has an associated private metadata stored in the Secret Contract. Pretty cool, right!
Note that this is for demo purposes only, if you were doing this in production you should use a more secure way of linking the EVM NFT to the Secret Network sister contract, such as a ZK proof.
Now let's deploy our EVM Minting contract 😊
cd
into evm-contract:
Install the dependencies:
Create a .env
file and add your EVM PRIVATE_KEY
and Infura API Key for Sepolia testnet:
Once you have your env file configured, upload the minting contract:
Upon successful upload, a contract address will be returned:
Congrats! You now have a private metadata contract deployed on Secret Network and a minting contract deployed on Sepolia testnet! Now let's learn how to use SecretPath to send data confidentially from the EVM to Secret Network 😎
It's time to connect your EVM minting contract and your Secret confidential metadata contract to a frontend and SecretPath! You will need to create a Pinata JWT key as well as an OpenAI API key, which is outlined below :D
cd into secretpath-nft/frontend and install the dependencies:
Create an env
and add the following:
Once you have added all of your environment variables, it's time to execute the contracts with our frontend!
We will dive into the SecretPath code shortly, but first, let's create your first cross-chain NFT with SecretPath :D
cd into frontend:
Then run the program:
The frontend is designed so that the description of your NFT will be sent to OpenAI to as the prompt to generate your NFT image. So choose wisely, or not. 😂
The NFT confidential message and password is stored in your Secret Contract, which is linked to the tokenID of the NFT stored on Ethereum. Only your unique password can reveal the private metadata.
Once you mint your NFT, navigate to opensea testnet to see it in all its glory.
Better yet, view the NFT on your frontend to see it paired with the Secret Network sister contract with confidential metadata:
Congrats on minting your first cross-chain encrypted NFT! 🚀
Let's walkthrough the minting steps, and then examine the SecretPath code:
Pin the newly generated image with Pinata to create the token URI
Mint the NFT on Sepolia with your token URI
Send the confidential metadata to your Secret Contract with SecretPath
The majority of the SecretPath encryption code is boilerplate; you don't need to change a thing!
The only code you are updating is:
the Secret Network contract address + codeHash
the data
that you pass to the Secret Network sister contract
and the handle function that you are calling in the Secret sister contract
The execute_store_confidential_metadata
handle executes the handle in the Secret Network sister contract
SecretPath allows EVM developers to leverage Secret Network as a Confidential Computation Layer (CCL) for EVM-compatible chains, enabling cross-chain NFTs with confidential metadata. This tutorial guides developers through minting an NFT on Sepolia testnet, using a sister contract on Secret Network to store private metadata accessible only via a private password in the Secret Contract. The process includes generating an NFT image with OpenAI, pinning it with Pinata, minting the NFT on Sepolia, and sending confidential metadata to Secret Network using SecretPath.
Note: the end user of the application is not exposed to Secret Network and is only working directly in the EVM environment. However, the data is fully protected and cannot be viewed by anyone because it is stored in encrypted Secret contracts 😮💨
If you have any questions or run into any issues, post them on the Secret Developer Discord and somebody will assist you shortly.