Skip to content

Latest commit

 

History

History
1001 lines (770 loc) · 43.9 KB

_SETUP.md

File metadata and controls

1001 lines (770 loc) · 43.9 KB

Setup and Usage

Table of contents

Usage Guidelines

Start Here with section Setup Secret and follow the instructions from there.

Help judges and other developers understand the project.

See the DEMO_AND_VIDEO file for details.

  • IMPORTANT: Private secret contract on Secret Network must be deployed before deploying EVM gateway contract since it must be modified to include its address routing_info and code hash routing_code_hash.

  • NOTE: The public key of the user that deploys the custom Nunya.Business contract is sent through to the custom EVM Gateway contract so only that user may call that custom EVM Gateway contract, however we actually want to try and use the default EVM Gateway contract that has been deployed by the Secret network team with minimal changes and move the logic to the Secret contract instead. Apart from the creator of the Nunya.Business contract, the only other users that call any Secret network functions are accounts whose public keys are provided by the creator of the Nunya.Business giving those accounts permission to call the withdraw function.

Setup Frontend and Solidity Contracts

Requirements

Before you begin, you need to install the following tools:

Quickstart

To get started, follow the steps below:

  1. Install dependencies:
yarn install
  1. Configure environment variables
  • Hardhat

Copy the example and add the relevant keys from https://etherscan.io/ and https://account.getblock.io and https://dashboard.alchemy.com/apps.

Note that Alchemy does not support Ethereum Sepolia, so use Geoblocks instead to get an API key for Ethereum Sepolia JSON-RPC.

cp ./packages/hardhat/.env.example ./packages/hardhat/.env

Verify the contents of ./packages/hardhat/hardhat.config.ts

IMPORTANT: Update Gateway.sol to change the value of task_destination_network and secret_gateway_signer_address to be the deployed Gateway address on the Mainnet or Testnet or Localhost of the Secret Network, to match the value stored in ./packages/secret-contracts-scripts/src/config/deploy.ts, and comment out the values for the network not being used.

  • Nextjs

Use the same Alchemy API key. Obtain a WalletConnect project ID at https://cloud.walletconnect.com

cp ./packages/nextjs/.env.example ./packages/nextjs/.env

Verify the contents of ./packages/nextjs/scaffold.config.ts

  1. Setup network
  • Local Network (on remote machine)

  • Connect to Linode (e.g. in the example shown below the Linode server IP address is 172.105.184.209)

If you want to run a local network:

Note: Use accounts: [deployerPrivateKey] or accounts: { mnemonic: MNEMONIC } in ./packages/hardhat/hardhat.config.ts and specify the IP Address where it is being run.

  • Terminal 1
yarn hardhat:chain
  • Note: It is necessary to restart the chain after chaining the EVM Gateway code, otherwise it may deploy the EVM Gateway to a different address

Example output:

Started HTTP and WebSocket JSON-RPC server at http://172.105.184.209:8545/

Accounts
========
...
  • Compile and Deploy to Local Network
nvm use lts/hydrogen
yarn hardhat:clean
yarn hardhat:compile
yarn hardhat:deploy --network localhost

This command starts a local Ethereum network using Hardhat. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in packages/hardhat/hardhat.config.ts.

  • Testnet

Check configured correctly.

yarn hardhat:clean
yarn hardhat:compile
yarn hardhat:deploy --network sepolia

Note: The contract is located in packages/hardhat/contracts and can be modified to suit your needs. The yarn hardhat:deploy command uses the deploy script located in packages/hardhat/deploy to deploy the contract to the network. You can also customize the deploy script.

Note: If it has deployed previously it will output Nothing to compile. No need to generate any newer typings.. To make a fresh deployment first run yarn run hardhat:clean from the project root folder.

Example of output:

Generating typings for: 9 artifacts in dir: typechain-types for target: ethers-v6
Successfully generated 20 typings!
Compiled 9 Solidity files successfully (evm target: paris).
network:  sepolia
chain id:  11155111
hre.network.name:  sepolia
deployerAddress:  0x83De04f1aad8ABF1883166B14A29c084b7B8AB59
Deployer account balance: 6.938448757518362804 ETH
deploying "NunyaBusiness" (tx: 0x95ce8c146374df85ce0f0f5425e65a2e33092a74b972495c005fa038fe094d33)...: deployed at 0xAFFF311821C3F3AF863C7103BB17BDC1Ba04603D with 2871810 gas
Successfully deployed NunyaBusiness to address:  0xAFFF311821C3F3AF863C7103BB17BDC1Ba04603D
deploying "Gateway" (tx: 0x0c5c2b097801afec5518d3714095569b7df2a53dcde0802c192d036dbd95a66a)...: deployed at 0x1E4B12A9F82b33DA1127B27861EFf5E652de7a6F with 3337833 gas
Successfully deployed Gateway to address:  0x1E4B12A9F82b33DA1127B27861EFf5E652de7a6F
setGatewayAddressTx tx hash: 0xefc300507bbddb3ca95dc178d95b857a3771fd0a0334626f036edfe6ffda4343
👋 Nunya contract: 0xAFFF311821C3F3AF863C7103BB17BDC1Ba04603D
NunyaBusiness balance:  0.0005
Gateway balance:  0.0

Warning: Do not rename 01_deploy_your_contract.ts to 00_deploy_your_contract.ts or it will only compile but will not deploy

  1. Add the deployed Nunya.business Contract Address to nunyaBusinessContractAddress and Gateway address gatewayContractAddress for the relevant network in ./nunya/packages/secret-contracts-scripts/src/config/deploy.ts

  2. Call the Nunya.business Contract setEVMGatewayAddress function to set the Gateway EVM address in its state.

  • Run script:
yarn run secret:setEVMGatewayAddress

Example transaction hash: https://sepolia.etherscan.io/tx/0xef7a241e3eba870138323440e910e2a0e608654a46bd7720af8e03ed63618f3a

  1. View the contract in block explorer (if not deploying to localhost)

Example previous deployment: NunyaBusiness: https://sepolia.etherscan.io/address/0xAFFF311821C3F3AF863C7103BB17BDC1Ba04603D#code

Gateway: https://sepolia.etherscan.io/address/0x1E4B12A9F82b33DA1127B27861EFf5E652de7a6F#code

  1. Interact with deployed EVM Gateway via the NunyaBusiness contract

Assumes that you have already uploaded and instantiated the custom Secret contract in the Setup Secret Contracts section.

Skip to the submitRequestValue step in the Setup Secret Contracts section.

  1. On a third terminal, start the Nunya NextJS app:
yarn start

Visit app on: http://localhost:3000. You can interact with your smart contract using the Debug Contracts page. You can tweak the app config in packages/nextjs/scaffold.config.ts.

Run smart contract test with yarn hardhat:test

  • Edit smart contracts such as NunyaBusiness.sol in packages/hardhat/contracts
  • Edit frontend homepage at packages/nextjs/app/page.tsx. For guidance on routing and configuring pages/layouts checkout the Next.js documentation.
  • Edit deployment scripts in packages/hardhat/deploy

Setup Secret Contract

Install Dependencies

  • Install Git and Make - https://docs.scrt.network/secret-network-documentation/development/readme-1/setting-up-your-environment#install-requirements

  • Install Rust

    rustup update
    rustup default stable
    rustup target add wasm32-unknown-unknown
    source "$HOME/.cargo/env"
    
  • Install Cargo Generate

    cargo install cargo-generate --features vendored-openssl
    
  • Install dependencies

    nvm use
    npm install --global lerna
    yarn set version 4.5.3
    corepack enable
    corepack prepare [email protected] --activate
    
  • Install SecretCLI on Linux

    wget https://github.com/scrtlabs/SecretNetwork/releases/download/v1.15.0-beta.18/secretcli-Linux
    chmod +x secretcli-Linux
    mv secretcli-Linux /usr/bin/secretcli
    echo 'PATH=/usr/bin/secretcli:$PATH' >> ~/.bashrc && source ~/.bashrc
    secretcli --help
Deploy Gateway and Relayer of SecretPath on Localhost
  • Connect to Linode. Note: Replace the IP address with the address of your remote server.
  • Start Localhost server with chain-id secretdev-1
cd ./packages/secret-contracts/secret-gateway
docker stop secretdev && docker rm secretdev
make start-server
  • Ports:

  • Note: Localhost accounts that each have an initial balance of 1000000000000000000uscrt

a
secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03
A07oJJ9n4TYTnD7ZStYyiPbB3kXOZvqIMkchGmmPRAzf
grant rice replace explain federal release fix clever romance raise often wild taxi quarter soccer fiber love must tape steak together observe swap guitar

b
secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne
AgGQoJ1UiOfUW1PKCAnoYS
jelly shadow frog dirt dragon use armed praise universe win jungle close inmate rain oil canvas beauty pioneer chef soccer icon dizzy thunder meadow

c
secret1ajz54hz8azwuy34qwy9fkjnfcrvf0dzswy0lqq
AvK5BGEsO3kikflW0NlfV9cdVJcxVJgLh7tgh4TGS3Cg
chair love bleak wonder skirt permit say assist aunt credit roast size obtain minute throw sand usual age smart exact enough room shadow charge

d
secret1ldjxljw7v4vk6zhyduywh04hpj0jdwxsmrlatf
AzBzrKqSZp3YXMzITB8ZAqYysO0YCjtV
word twist toast cloth movie predict advance crumble escape whale sail such angry muffin balcony keen move employ cook valve hurt glimpse breeze brick

Deploy Relayer of SecretPath on Localhost

Deploy Gateway of SecretPath on Localhost
  • Clone the Github repo containing the Secret Gateway and initialise the submodules
mkdir -p github/ltfschoen && cd github/ltfschoen
git clone https://github.com/svub/nunya
cd nunya
git fetch origin submit-pubkey:submit-pubkey
git checkout submit-pubkey
cd packages/secret-contracts/secret-gateway
git submodule update --init --recursive
  • Terminal Tab 1: Install Docker if necessary

    • MacOS: Install Docker for Mac
    • Linux: Run the following and set a password
      sudo apt-get remove docker docker-engine docker.io containerd runc
      sudo apt-get update && sudo apt-get upgrade -y \
      && sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y \
      && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - \
      && sudo apt-key fingerprint 0EBFCD88 \
      && sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
      && sudo apt-get update \
      && sudo apt-get install docker-ce docker-ce-cli containerd.io -y \
      && adduser user \
      && usermod -aG docker user \
      && systemctl restart docker \
      && systemctl enable docker \
      && sudo apt-get install -y docker-compose-plugin
  • Terminal Tab 1: Secret Localhost (Localsecret)

    make start-server
    
  • Terminal Tab 2: Option A (SecretJS) Compile, Upload, Instantiate:

    • Change back to the project root directory
    • Run the following on the local machine to copy the relevant environment variables to the remote machine
      REMOTE_IP=172.105.184.209
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/hardhat/.env
      DESTINATION=/root/nunya/packages/hardhat/.env
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/.env
      DESTINATION=/root/nunya/packages/secret-contracts-scripts/.env
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
      DESTINATION=/root/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
      • UPDATE CONFIG gatewayContractAdminAddress before deploy Secret Gateway
    SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
    DESTINATION=/root/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
    scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
    • Linux, or, install NVM, then:

      apt update
      nvm install lts/hydrogen
      nvm use lts/hydrogen
      npm install -g yarn
      npm install -g corepack
      yarn set version 4.5.3
      corepack enable
      corepack prepare [email protected] --activate
      
      # we need the latest ABI file to be generated /hardhat/artifacts/contracts/Gateway.sol/Gateway.json
      # since it is used in the Secret network script `secret:uploadGateway`
      yarn hardhat:clean
      yarn hardhat:compile
      
      yarn install
      yarn run secret:clean
      yarn run secret:uploadGateway
      
      • Note: If you get error TypeError: URL.canParse is not a function then you're likely using the wrong Node.js version, so just change to the project root directory and run nvm use in that terminal tab.
    • Add the CODE_ID to secretGateway -> gatewayContractCodeId and CODE_HASH to secretGateway -> gatewayContractCodeHash respectively to the relevant config.secret. in ./packages/secret-contracts-scripts/src/config/deploy.ts

    • Add the terminal log to ./logs_secret/uploadGatewaySecretLocalhost.log

    IMPORTANT: If deployment of the code with await secretjs.tx.compute.storeCode is unsuccessful, then check if Beta version of secretjs is necessary incase the Secret Testnet is being upgraded.

    IMPORTANT: If the CODE_HASH changes due to changes in the Secret Gateway codebase, it is also necessary to update the code_hash in the Relay to match it.

    yarn run secret:instantiateGateway
    
    • Add the SECRET_ADDRESS to gatewayContractAddress in the relevant config.secret. in ./nunya/packages/secret-contracts-scripts/src/config/deploy.ts

    • Add the terminal log to ./logs_secret/instantiateOutput.log

    • Add the Secret Localhost chain logs to ./logs_secret/instantiateGatewaySecretLocalhostChainOutput.log

    • View on Secret Localhost block explorer

    • Reference https://docs.scrt.network/secret-network-documentation/development/readme-1/compile-and-deploy

    • Note: In order to populate the secret.localhost.secretGateway.gatewayContractPublicKey and secret.localhost.secretGateway.gatewayContractEncryptionKeyForChaChaPoly1305 do the following:

    • Get the Secret Gateway public key (signing verification key '0x' prefixed hex string) and base64 encryption key

    yarn run secret:querySecretGatewayPubkey

    Example output:

     res queryPubkey:  {
       encryption_key: '...',
       verification_key: '0x...'
     }
    
    • Paste verification_key into Gateway.sol for value of secret_gateway_signer_pubkey

    • Redeploy if differs Gateway.sol

      • Paste them into deploy.ts, gatewayContractPublicKey with verification_key and gatewayContractEncryptionKeyForChaChaPoly1305 with encryption_key
    • NEXT, Deploy Nunya Contract on Localhost

  • IGNORE - Terminal Tab 2: Option B (SecretCLI) Compile, Upload, Instantiate:

    • Compile. Note: Outputs contract.wasm or contract.wasm.gz file in the root directory being the ./SecretPath/TNLS-Gateways/secret/ folder. Using make build-mainnet-reproducible will remove contract.wasm so only the optimised contract.wasm.gz remains. Warning: If you only run make build-mainnet then you will get this error #8 when deploying.

      • Secret Gateway Contract. Note: Wait until the Docker container exists first.
        make clean
        make build
        
    • Note: Use existing secretdev Docker container that is running already.

    • Copy compiled Secret Gateway contract to the Docker container

      make copy-secret-gateway-contract-local
      
    • Store compiled Secret Gateway contract on Localhost (Localsecret network)

      make store-secret-gateway-contract-local
      
      • Optional: To enter the Docker container to interact manually with secretcli:

        docker exec -it secretdev /bin/bash
        secretcli --help
        secretcli keys list
        ls /root/.secretd/config
      • Example output:

        {"height":"0","txhash":"A5A2E9864A3F455AD503935AE739B4E898F71A5B5BFCDB7B7D6934942297223C","codespace":"","code":0,"data":"","raw_log":"","logs":[],"info":"","gas_wanted":"0","gas_used":"0","tx":null,"timestamp":"","events":[]}
        
      • Note that in the Secret Localsecret chain logs it output num_txs=1:

        11:43AM INF finalizing commit of block hash=9B39F1E7367B876F61E45CFD0DE3EC55CE59D140A4604E35622D8C6CDEE1BB66 height=115 module=consensus num_txs=1 root=371919C2BE93B7F0C2B81837770B871592793F8A74847C04593F27F8A62109A1
        
        • TODO: Why didn't it output "height":"115" instead of "height":"0"?
        • TODO: Why doesn't it output the CODE_ID and CODE_HASH? Use Option A instead until resolve this issue.
Deploy Relayer of SecretPath on Localhost
  • Clone the Relayer Github repo and initialise the submodules
mkdir -p ltfschoen && cd ltfschoen
git clone https://github.com/ltfschoen/SecretPath
git fetch origin nunya:nunya
git checkout nunya
cd SecretPath/TNLS-Relayers
  • Check that it is using the latest version of the Python secret-sdk in requirements.txt https://github.com/secretanalytics/secret-sdk-python/releases

  • Configure the Relayer

  • Edit ./SecretPath/TNLS-Relayers/.env

    cp ./SecretPath/TNLS-Relayers/.env.example ./SecretPath/TNLS-Relayers/.env
    
    • IGNORE - Generate an Ethereum wallet with address, private key, mnemonic phrase, and encrypted JSON file using MyCrypto desktop from Github https://github.com/MyCryptoHQ/MyCrypto/releases/tag/1.7.17 and ensure that you verify the checksum of the download. Import that into Keplar browser extension using the private key to obtain the associated Secret Network address. Verify that the Ethereum address on the Ethereum Network in the Keplar wallet once imported matches the Ethereum address that was chosen.

    • Localhost

      • Add for Localhost of Ethereum the private key into ethereum-private-key = XXXXX of the .env file /Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/.env

        • IMPORTANT: Exclude the leading 0x
      • Create a new Keplar Wallet that must use Google to generate an associated private key.

        • Add for Localhost of Secret Network the private key to secret-private-key = XXXXX associated with that address (e.g. secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg)
          • IMPORTANT: Exclude the leading 0x
    • Testnet

      • Add for Ethereum Sepolia the private key into ethereum-private-key = XXXXX of the .env file /Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/.env to be the same as DEPLOYER_PRIVATE_KEY

        • IMPORTANT: Exclude the leading 0x
      • TODO - similar to approach used on Localhost for Secret Network

        • IMPORTANT: Exclude the leading 0x
  • If you edit the config.yml file on your local machine (instead of directly on the server), copy it to the server

    REMOTE_IP=172.105.184.209
    SOURCE=/Users/luke/code/clones/github/ltfschoen/SecretPath/TNLS-Relayers/config.yml
    DESTINATION=/root/ltfschoen/SecretPath/TNLS-Relayers/config.yml
    scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
    
    REMOTE_IP=172.105.184.209
    SOURCE=/Users/luke/code/clones/github/ltfschoen/SecretPath/TNLS-Relayers/.env
    DESTINATION=/root/ltfschoen/SecretPath/TNLS-Relayers/.env
    scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
    
    REMOTE_IP=172.105.184.209
    SOURCE=/Users/luke/code/clones/github/ltfschoen/SecretPath/TNLS-Relayers/base_interface.py
    DESTINATION=/root/ltfschoen/SecretPath/TNLS-Relayers/base_interface.py
    scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
    
    REMOTE_IP=172.105.184.209
    SOURCE=/Users/luke/code/clones/github/ltfschoen/SecretPath/TNLS-Relayers/scrt_interface.py
    DESTINATION=/root/ltfschoen/SecretPath/TNLS-Relayers/scrt_interface.py
    scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
    
  • IGNORE - Transfer some Localhost Ethereum tokens from a default account like Account #0 that is shown when running Ethereum Localhost to that Ethereum wallet address associated with the private key ethereum-private-key.

    Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH)
    privateKey: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
    
    • TODO - is this necessary? why not just use the default account?
  • Transfer some Localhost Secret tokens from a default account that is shown when running Secret Localhost (e.g. secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03) to that Secret wallet address (e.g. secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg).

    docker exec -it secretdev /bin/bash
    secretcli config view
    secretcli config set client node tcp://localhost:26657
    secretcli config set client chain-id secretdev-1
    secretcli config set client output json
    secretcli config set client keyring-backend test
    secretcli config view client --output-format json
    secretcli config home
    
    secretcli query bank balances secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 | jq
    secretcli query bank balances secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg | jq
    
    • Note: Configuration is stored in /root/.secretd/config/client.toml
    • Note: keyring-backend is where the keys are stored from possible options including: (os|file|kwallet|pass|test|memory)
    • Note: We need the 300000uscrt to process the broadcast the submitRequestValue transaction from the relayer, so give them more than that.
    • Note: If you forget to do this before running the relayer, then you might get error [SCRT Interface: ERROR] Failed to fetch account info: HTTP 404
    secretcli tx bank send secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg 100000000000000000uscrt -y
    
    secretcli query bank balances secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg | jq
    
    • Note: This is necessary because the default account only has a mnemonic phrase, not a private key.

    • IGNORE

      a_mnemonic="grant rice replace explain federal release fix clever romance raise often wild taxi quarter soccer fiber love must tape steak together observe swap guitar"
      echo $a_mnemonic | secretcli keys add account --recover
      secretcli keys show account
      
      # it should output `secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03`
      
      b_mnemonic="jelly shadow frog dirt dragon use armed praise universe win jungle close inmate rain oil canvas beauty pioneer chef soccer icon dizzy thunder meadow"
      echo $b_mnemonic | secretcli keys add account2 --recover
      secretcli keys show account2
      
      # it should output `secret1fc3fzy78ttp0lwuujw7e52rhspxn8uj52zfyne`
      
      custom_mnemonic="<INSERT_MNEMONIC_PHRASE>"
      echo $custom_mnemonic | secretcli keys add custom --hd-path="m/44'/60'/0'/0" --recover
      secretcli keys show custom
      
  • Install Miniconde

Configure

Deploy Nunya Contract on Localhost
Testnet
  • Edit config.secret.network to be "testnet"
Localhost
  • Edit config.secret.network to be "localhost"
    • Ensure ENDPOINT_LOCAL is set to where you are running the Secret Localhost (e.g. http://<IP_ADDRESS>:1317)
    • Ensure that secretGateway -> address, gatewayContractCodeHash, gatewayPublicKey, and gatewayEncryptionKeyForChaChaPoly1305 and set to where you deployed the Gateway on Localhost

Create, Compile and Deploy (Upload and Instantiate) Secret Contract

Create, Compile
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install llvm
llvm-config --version
echo "export AR=$(which llvm-ar)" >> ~/.zshrc
echo "export CC=$(which clang)" >> ~/.zshrc
source ~/.zshrc
  • Run Docker (e.g. Docker Desktop on macOS)

  • Remove any old Docker containers, if necessary

docker rmi sco
  • Compile. Note: Outputs contract.wasm and contract.wasm.gz file in the root directory of the secret-contracts/nunya-contract folder. Using make build-mainnet-reproducible will remove contract.wasm so only the optimised contract.wasm.gz remains. Warning: If you only run make build-mainnet then you will get this error #8 when deploying.
Testnet
  • Nunya Contract
    cd packages/secret-contracts/nunya-contract
    make clean
    make build-mainnet-reproducible
    

OR

  • My Counter Contract (Example only)
    cd packages/secret-contracts/my-counter-contract
    make clean
    make build-mainnet-reproducible
    
Localhost
  • Nunya Contract
    cd packages/secret-contracts/nunya-contract
    make clean
    make build
    
Deploy (Upload and Instantiate)
Testnet
  • Upload and Instantiate

IMPORTANT: Prior to Upload step it is necessary to recompile changes if any.

IMPORTANT: Prior to Upload step it is necessary to configure the wallet, network, and endpoint to use either Local or Testnet, and to specify what project's compiled smart contract WASM file to use and whether to use the optimized build (e.g. ./nunya-contract/optimized-wasm/secret_evm_storage.wasm.gz or ./nunya-contract/contract.wasm.gz) in the script ./packages/secret-contracts-scripts/src/index.ts

IMPORTANT: Prior to Instantiation step it is necessary to deploy the EVM Gateway

  • Update the secretjs dependency in ./packages/secret-contracts-scripts/package.json to use a version from https://github.com/scrtlabs/secret.js/tags that works (e.g. 1.15.0-beta.1) by asking the Secret Network team. Use 1.15.0-beta.1. Note that 1.15.0-beta.2 may only upload but does not instantiate. Note that 1.15.0-beta.0 does not upload at all.

IMPORTANT: Errors deploying may be because of mismatched types, for example InstantiateMsg here https://github.com/svub/nunya/blob/45e884194e8183229e3d7c61ccba7d789ff996b1/packages/secret-contracts/nunya-contract/src/msg.rs#L16C12-L16C26 must match here

IMPORTANT: Both upload and instantiate must be performed using the same version of secretjs

yarn install
cd ../../../
yarn run secret:clean
yarn run secret:upload
  • Add the CODE_ID to codeId and CODE_HASH to secretNunya -> nunyaContractCodeHash respectively to the relevant config.secret. in ./packages/secret-contracts-scripts/src/config/deploy.ts
  • Add the terminal log to ./logs_secret/uploadOutput.log

IMPORTANT: If deployment of the code with await secretjs.tx.compute.storeCode is unsuccessful, then check if Beta version of secretjs is necessary incase the Secret Testnet is being upgraded.

yarn run secret:instantiate
Localhost
  • Terminal Tab 1

    • Note: Only run `make start-server if not already running
    make start-server
    • Note: docker logs -f --tail 10 secretdev to view its logs
  • Terminal Tab 2: Option A (SecretJS) Compile, Upload, Instantiate:

    • Change back to the project root directory

    • Run the following on the local machine to copy the relevant environment variables to the remote machine

      REMOTE_IP=172.105.184.209
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/hardhat/.env
      DESTINATION=/root/nunya/packages/hardhat/.env
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/.env
      DESTINATION=/root/nunya/packages/secret-contracts-scripts/.env
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
      DESTINATION=/root/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
    • Linux, or, install NVM, then:

      apt update
      nvm install lts/hydrogen
      nvm use lts/hydrogen
      npm install -g yarn
      npm install -g corepack
      yarn set version 4.5.3
      corepack enable
      corepack prepare [email protected] --activate
      
      # we need the latest ABI file to be generated /hardhat/artifacts/contracts/NunyaBusiness.sol/NunyaBusiness.json
      # since it is used in the Secret network script `secret:upload`
      yarn hardhat:clean
      yarn hardhat:compile
      
      yarn install
      yarn run secret:clean
      yarn run secret:upload
      
    • Add the CODE_ID to secretNunya -> nunyaContractCodeId and CODE_HASH to secretNunya -> nunyaContractCodeHash respectively to the relevant config.secret. in ./packages/secret-contracts-scripts/src/config/deploy.ts

    • Add the terminal log to ./logs_secret/uploadNunyaSecretLocalhost.log

    IMPORTANT: If deployment of the code with await secretjs.tx.compute.storeCode is unsuccessful, then check if Beta version of secretjs is necessary incase the Secret Testnet is being upgraded.

    yarn run secret:instantiate
    
  • IGNORE - Option B:

make copy-nunya-contract-local
make store-nunya-contract-local
  • TODO: How to configure the Secret Gateway in Nunya Secret Contract?

Interact with Deployed Secret Contract via Deployed EVM Gateway to submitRequestValue

Localhost
* Record logs from Localsecret since the output is too long otherwise. Press CTRL+C to cancel when PostExecution occurs in Ethereum Local Network logs to indicate it has finished. 
	```bash
	docker logs -f secretdev | tee ~/nunya/docker.log
	```

* Run end-to-end transaction

	```bash
	cd ~/nunya
	nvm use
	yarn run secret:submitRequestValue
	```

* Copy Localsecret logs from remote machine to local.  
	```bash
	REMOTE_IP=172.105.184.209
	SOURCE=/root/nunya/docker.log
	DESTINATION=/Users/luke/code/clones/github/svub/nunya
	scp -r root@$REMOTE_IP:$SOURCE $DESTINATION
	```
Testnet

TODO

Interact with Deployed Secret Contract via Deployed EVM Gateway to submitRequestValue

Localhost
  • Record logs from Localsecret since the output is too long otherwise. Press CTRL+C to cancel when PostExecution occurs in Ethereum Local Network logs to indicate it has finished.
    docker logs -f secretdev | tee ~/nunya/docker.log
  1. Script submitRequestValue.ts
    • Run end-to-end transaction

       yarn run secret:submitRequestValue
  • View logs. Use console.log in Solidity

  • Note: To quickly rebuild and redeploy if Solidity files get changed run the following:

    • Local machine
      REMOTE_IP=172.105.184.209
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/hardhat/contracts/Gateway.sol
      DESTINATION=/root/nunya/packages/hardhat/contracts/Gateway.sol
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
      REMOTE_IP=172.105.184.209
      SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/src/submitRequestValue.ts
      DESTINATION=/root/nunya/packages/secret-contracts-scripts/src/submitRequestValue.ts
      scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
      
    • Remote server
      • Terminal 1

        yarn hardhat:chain
        
      • Terminal 2

        yarn hardhat:clean && yarn hardhat:compile && yarn hardhat:deploy --network localhost
        
        • Update deploy.ts with an updated gateway deployment address if it changed
        • Copy it across if it changes:
          REMOTE_IP=172.105.184.209
          SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/hardhat/.env
          DESTINATION=/root/nunya/packages/hardhat/.env
          scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
          
          SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/.env
          DESTINATION=/root/nunya/packages/hardhat/.env
          scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
          
          SOURCE=/Users/luke/code/clones/github/svub/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
          DESTINATION=/root/nunya/packages/secret-contracts-scripts/src/config/deploy.ts
          scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
          
        yarn run secret:setEVMGatewayAddress && yarn run secret:submitRequestValue
        
      • View logs in both terminals

      • Add log outputs to:

        • ./logs_secret/submitRequestValueLocalhostEthereumLogs.log - Logs from the JavaScript in terminal where you run yarn run secret:submitRequestValue
        • ./logs_secret/submitRequestValueLocalhostRelayerLogs.log - Logs from Relayer
        • ./logs_secret/submitRequestValueLocalhostSecretLogs.log - Logs from Secret Network running locally
        • ./logs_secret/submitRequestValueLocalhostEthereumLogs.log - Logs from Ethereum Network running locally
  1. Remix
  • If necessary, similar to how used with Testnet below
Testnet

Options:

  1. Script submitRequestValue.ts

    yarn run secret:submitRequestValue
  2. Remix

  • FIXME - the below is outdated and needs to be updated

  • Interact with the deployed Gateway EVM contract on Sepolia Ethereum

    • Open Remix https://remix.ethereum.org/
      • Choose "File explorer" tab on the left
      • Choose "Upload Folder" icon
      • Choose the contracts folder ./svub/nunya/packages/hardhat/contracts containing the Solidity files
      • Gateway.sol
        • Open Gateway.sol
          • Click compile icon
        • Choose "Solidity compiler" tab on the left
        • Choose version 0.8.28
        • Click "Compile Gateway.sol" and view the warnings by scrolling down
        • Choose "Deploy and run transactions" tab on the left
        • Click "Environment" and choose "Customize this list..."
          • Select "Sepolia Testnet - Metamask"
        • Click "Sepolia Testnet - Metamask" from the "Environment" drop-down list
        • Allow Metamask to switch to Sepolia network in the popup that appears
        • Open Metamask and click the Remix icon and choose to "Connect more accounts..." to remix.ethereum.org and connect the address associated with the DEPLOYER_ADDRESS used in the .env file
        • Select "Account" to be that DEPLOYER_ADDRESS
        • Enter the deployed Gateway EVM address on Sepolia Testnet (e.g. mentioned in ./nunya/packages/secret-contracts-scripts/src/config/deploy.ts) and click "At Address"
        • Scroll down to the "Deployed Contracts" section that is autogenerated to interact with the deployed contract
        • Click "secret_gateway_signer_address" to call the Gateway contract getter for that constant and return its value that should be shown as 0x2821E794B01ABF0cE2DA0ca171A1fAc68FaDCa06
      • NunyaBusiness.sol
        • Repeat relevant initial steps above for NunyaBusiness.sol
        • Enter the deployed NunyaBusiness EVM address on Sepolia Testnet (e.g. mentioned in ./nunya/packages/secret-contracts-scripts/src/config/deploy.ts) and click "At Address"
        • Scroll down to the "Deployed Contracts" section that is autogenerated to interact with the deployed contract
        • Click setGatewayAddress to create a transaction after providing the following argument to call the NunyaBusiness contracts transaction using the latest value from ./nunya/packages/secret-contracts-scripts/src/config/deploy.ts
          • Retrieve its value by clicking to call CustomGateway
        • Click unsafeSetSecretContractInfo to create a transaction after providing the following arguments config.secret.testnet.secretNunya.nunyaContractCodeHash and config.secret.testnet.secretNunya.nunyaContractAddress using values from ./nunya/packages/secret-contracts-scripts/src/config/deploy.ts
          • Retrieve their values by clicking to calls routing_info and routing_code_hash
        • Click unsafeRequestValue to create a transaction after providing the following arguments 0xb6c2b131 and 10000000
Unsorted
Testnet
  • Query Pubkey
cd ../../../
yarn run secret:queryPubkey
  • TODO: Transaction secretContract.retrievePubkey
yarn run secret:submit

About Custom Gateways and Relayers

See https://github.com/ltfschoen/SecretPath for source code associated with the following:

  • Custom Public Gateway on Ethereum Sepolia
  • Custom Relay Network
  • Custom Private Gateway on Secret Network

The deployed NunyaBusiness.sol contract on Ethereum Sepolia shall interact with the Public Gateway.

The deployed Nunya Secret Private Contract on Secret Network shall interact with the Private Gateway on Secret Network