Skip to main content
Deploy the latest code and to Virtual Environments make it available for your team by sharing the RPC link and contract addresses.
Continuous integration (CI) and continous deployment (CD) with Virtual Environments

Code Sample: Staging Contracts to Virtual Environment

REST API: Create and manage Virtual Environments

1
Create a Virtual Environment
2
Create a new Virtual Environment to stage your contracts, either by:
4
Set up environment variables
5
To create a Virtual Environment and then deploy and verify contracts, set up the following environment variables:
6
  • TENDERLY_ACCOUNT_ID with your account ID
  • TENDERLY_PROJECT with your project (slug)
  • TENDERLY_ACCESS_KEY with the access key you’ve generated
  • ORIGINAL_NETWORK_ID with the ID of the network you want to base the Virtual Environment on
  • FOUNDRY_REPO with the path to Foundry repo
  • DEPLOYER_ADDRESS with the account you’re deploying from
  • Add other environment variables needed for the deployment scripts
  • 7
    export TENDERLY_ACCOUNT_ID=<USERNAME>
    export TENDERLY_PROJECT=<PROJECT>
    export TENDERLY_ACCESS_KEY=<ACCESS_KEY>
    
    ## TestNet Configuration
    export TENDERLY_TESTNET_NAME=staging
    export PURPOSE=development
    export ORIGINAL_NETWORK_ID=1
    export BLOCK_NUMBER=latest
    
    ## Custom Chain ID (Prefixed with 7357 - test)
    export CHAIN_ID=7357$ORIGINAL_NETWORK_ID
    
    ## Public explorer verification visibility
    ## abi | full | none
    export VERIFICATION_VISIBILITY=abi
    
    # Foundry Repo (Absolute path only!)
    export FOUNDRY_REPO=<ABSOLUTE PATH TO FOUNDRY PROJECT>
    
    ## Deployer address
    export DEPLOYER_ADDRESS=...
    
    ## Custom stuff needed for deployment scripts
    ## Add your custom stuff here
    export ADMIN_ADDRESS=...
    
    8
    Write your deployment commands
    9
    Edit deploy-command.sh and add commands to deploy your contracts. Note you’ll have to add verification to your Foundry or Hardhat project; see Deploy and verify contracts.
    10
    For example:
    11
    #!/bin/bash
    
    cd $FOUNDRY_REPO
    
    ## TODO: Your deployment command here:
    MAX_SEGMENT_COUNT=3
    
    FOUNDRY_PROFILE=optimized \
    forge script script/DeployCore.s.sol \
      --broadcast \
      --rpc-url $TENDERLY_VIRTUAL_TESTNET_RPC \
      --sig "run(address)" \
      --verify \
      --verifier-url $VERIFICATION_URL \
      $ADMIN_ADDRESS
    
    12
    Stage contracts
    13
    Run the following commands that will:
    14
  • create a new Virtual Environment
  • fund the $DEPLOYER_ADDRESS with test ETH using the Infinite faucet
  • configure Foundry’s foundry.toml for verification on your custom chain
  • deploy your contracts
  • and finally clean up foundry.toml
  • 15
    # create a testnet - or paste the Unlocked TestNet RPC URL
    source src/contracts-staging/.env
    cd src/contracts-staging
    
    ## Create a fresh testnet
    export VIRTUAL_NETWORK_RPC_URL=$(./create-testnet.sh)
    echo "Created a Virtual Environment at ${VIRTUAL_NETWORK_RPC_URL}"
    
    ### run the deployment
    ./deploy-to-testnet.sh
    
    16
    The RPC Link is shown in the output, and your contracts are deployed and verified on the Virtual Environment.
    17
    Share the addresses
    18
    Collect the ABIs and addresses of deployed contracts and distribute them to your team, together with the Virtual Environment RPC.