### Install Dependencies and Start Dev Server (Shell) Source: https://www.zetachain.com/docs/developers/tutorials/frontend Commands to install project dependencies using Yarn and start the Vite development server. Assumes the user is in the `hello/frontend` directory. ```shell cd hello/frontend yarn yarn dev ``` -------------------------------- ### Clone Example Project and Install Dependencies Source: https://www.zetachain.com/docs/developers/tutorials/sui-withdraw-and-call This snippet demonstrates how to clone the example project for interacting with ZetaChain and Sui, and install its dependencies using yarn. ```bash npx zetachain@next new --project call cd call yarn ``` -------------------------------- ### Project Setup and Dependency Installation (NPM, Yarn, Forge) Source: https://www.zetachain.com/docs/developers/tutorials/sui This snippet demonstrates how to generate a new project using the ZetaChain CLI, navigate into the project directory, and install necessary dependencies using Yarn and Forge. It sets up a local development environment for interacting with Sui and ZetaChain. ```shell npx zetachain@latest new --project call cd call yarn forge soldeer update ``` -------------------------------- ### Project Setup and Localnet Initialization - Node.js Source: https://www.zetachain.com/docs/developers/tutorials/solana This snippet demonstrates setting up a new project for ZetaChain development and starting the local development environment that includes ZetaChain and Solana. It uses `npx` commands to manage project creation and yarn for dependency installation. ```bash npx zetachain@latest new --project call cd call yarn yarn zetachain localnet start ``` -------------------------------- ### Install and Run ZetaChain CLI Source: https://www.zetachain.com/docs/reference/cli Instructions on how to install the ZetaChain CLI globally or run it directly using npx. It also provides commands for creating new projects and starting a local multi-chain development environment. ```bash npx zetachain@next new npm install -g zetachain@latest zetachain new zetachain localnet start ``` -------------------------------- ### Install KSYNC (Go) Source: https://www.zetachain.com/docs/nodes/start-here/syncing Installs the latest version of KSYNC using the Go build tools. Ensure Go is installed and configured in your environment. ```bash go install github.com/KYVENetwork/ksync/cmd/ksync@latest ``` -------------------------------- ### Verify KSYNC Installation (Bash) Source: https://www.zetachain.com/docs/nodes/start-here/syncing Checks if the KSYNC installation was successful by displaying the installed version. This command should be run after the installation. ```bash ksync version ``` -------------------------------- ### Install Cosmovisor from Source Source: https://www.zetachain.com/docs/nodes/start-here/setup Installs Cosmovisor, a process manager for Cosmos SDK applications, directly from its source code using the go install command. The binary is then moved to a system-wide executable path. ```go go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.7.1 mv $(go env GOPATH)/bin/cosmovisor /usr/local/bin/cosmovisor ``` -------------------------------- ### Install ZetaChain Toolkit SDK Source: https://www.zetachain.com/docs/reference/toolkit Install the ZetaChain Toolkit using npm. This command adds the necessary library to your project for building universal applications. ```bash npm i @zetachain/toolkit ``` -------------------------------- ### Cloud-Init Configuration for ZetaChain Node Setup Source: https://www.zetachain.com/docs/nodes/validate/validator-gcp The main cloud-init configuration file that defines the overall setup process for a ZetaChain node. It includes package installations, user creation, and the paths to various setup scripts. ```yaml #cloud-config package_update: true package_upgrade: true packages: - curl - git - jq - lz4 - build-essential - unzip - mdadm users: - name: zetachain gecos: Zetachain lock_passwd: true write_files: - path: /etc/systemd/system/zetacored.service permissions: 0644 owner: root content: | [Unit] Description=zetacored (running under Cosmovisor) After=multi-user.target StartLimitIntervalSec=0 [Install] WantedBy=multi-user.target [Service] User=zetachain ExecStart=/usr/local/bin/cosmovisor run start --home /var/lib/zetacored/ --log_format json --moniker ${moniker} Restart=on-failure RestartSec=3 WorkingDirectory=/var/lib/zetacored/cosmovisor Environment="DAEMON_NAME=zetacored" Environment="DAEMON_HOME=/var/lib/zetacored" # Note that downloading binaries is enabled due to relatively short # release timescales for ZetaChain. Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=true" Environment="DAEMON_RESTART_AFTER_UPGRADE=true" Environment="DAEMON_DATA_BACKUP_DIR=/var/lib/zetacored" Environment="UNSAFE_SKIP_BACKUP=true" Type=simple LimitNOFILE=262144 - path: /usr/local/bin/setup-disk-array.sh permissions: "0744" content: | #!/bin/bash # Set up the RAID arrays. mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/nvme0n1 /dev/nvme0n2 mkfs.ext4 /dev/md0 echo "Created /dev/md0" # Add an fstab entry for the data directory. mkdir -p /var/lib/zetacored UUID=`sudo blkid -o value -s UUID /dev/md0` echo "UUID=$UUID /var/lib/zetacored ext4 defaults 0 0" >> /etc/fstab echo "Created fstab entries for /var/lib/zetacored" # Reload the systemd service after fstab is updated. systemctl daemon-reload # Mount the directory. mount /var/lib/zetacored - path: /usr/local/bin/configure-system-limits.sh permissions: "0744" content: | #!/bin/bash # Update system limits echo "* hard nproc 262144" >> /etc/security/limits.conf echo "* soft nproc 262144" >> /etc/security/limits.conf echo "* hard nofile 262144" >> /etc/security/limits.conf echo "* soft nofile 262144" >> /etc/security/limits.conf echo "fs.file-max=262144" >> /etc/sysctl.conf - path: /usr/local/bin/configure-zetacored.sh permissions: "0744" content: | #!/bin/bash CONFIG_TOML="/var/lib/zetacored/config/config.toml" APP_TOML="/var/lib/zetacored/config/app.toml" # Fetch a file from Cloud Storage if available. If not available, fetch from or GitHub then cache in Cloud Storage. fetch_config () { gsutil cp gs://${gcs_bucket_static}/network-config/${zetachain_network}/$1 /var/lib/zetacored/config/$1 if [ $? -eq 1 ]; then echo "Downloading $1 from GitHub" wget https://raw.githubusercontent.com/zeta-chain/network-config/main/${zetachain_network}/$1 -O /var/lib/zetacored/config/$1 gsutil cp /var/lib/zetacored/config/$1 gs://${gcs_bucket_static}/network-config/${zetachain_network}/$1 fi } # Initialize the Zetachain node. /usr/local/bin/zetacored init --home /var/lib/zetacored ${moniker} --chain-id ${zetachain_chain_id} if [ $? -eq 1 ]; then echo "Failed to initialize Zetachain node" exit 1 fi # Copy the network configuration files from Cloud Storage if available. fetch_config app.toml fetch_config client.toml fetch_config config.toml fetch_config genesis.json # Set the external IP address external_address=$(wget -qO- eth0.me) sed -i.bak -e "s/^moniker *=.*/moniker = \"${moniker}\"" $CONFIG_TOML sed -i.bak -e "s/^external_address *=.*/external_address = \"$external_address:26656\"" $CONFIG_TOML # Set up initial binary for Cosmosvisor mkdir -p /var/lib/zetacored/cosmovisor/genesis/bin mkdir -p /var/lib/zetacored/cosmovisor/upgrades cp /usr/local/bin/zetacored /var/lib/zetacored/cosmovisor/genesis/bin/zetacored echo "Installed Zetachain node to Cosmosvisor" # Fetch the state snapshot. gsutil cp gs://${gcs_bucket_static}/snapshot/${zetachain_network}/${zetachain_snapshot} /var/lib/zetacored/snapshot.tar if [ $? -eq 1 ]; then echo "Downloading state snapshot from ${zetachain_snapshot_host}" wget ${zetachain_snapshot_host}${zetachain_snapshot} -O /var/lib/zetacored/snapshot.tar ``` -------------------------------- ### Initialize Project and Install Dependencies (TypeScript) Source: https://www.zetachain.com/docs/about/services/goldrush This snippet shows how to set up a new project and install the necessary SDKs for interacting with the GoldRush API using Node.js and npm. ```shell mkdir zetachain-app cd zetachain-app npm init -y npm install @covalenthq/client-sdk axios ``` -------------------------------- ### Install Cosmovisor Binary Source: https://www.zetachain.com/docs/nodes/validate/validator-gcp This script builds and installs the Cosmovisor binary, a tool for managing Cosmos SDK nodes. It uses Go to install the specified version of Cosmovisor and then copies the executable to the system's binary path. Dependencies include Go and its toolchain. ```bash #!/bin/bash # Build the Cosmovisor binary. /usr/local/go/bin/go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.5.0 cp ~/go/bin/cosmovisor /usr/local/bin/ echo "Built Cosmovisor" ``` -------------------------------- ### Install ZetaChain Dependencies Source: https://www.zetachain.com/docs/developers/tutorials/frontend Installs the necessary dependencies for the ZetaChain project using yarn. This is a prerequisite for building web applications that interact with ZetaChain. ```bash cd hello/frontend yarn ``` -------------------------------- ### Setting Up ZetaChain Project Source: https://www.zetachain.com/docs/developers/tutorials/swap Commands to create a new ZetaChain project, install dependencies using yarn, update Solidity dependencies with Foundry's package manager, and compile the contract. ```bash zetachain new --project swap cd swap yarn forge soldeer update forge build ``` -------------------------------- ### Download and Extract Full Node Snapshot (Shell) Source: https://www.zetachain.com/docs/nodes/start-here/syncing This script automates the process of downloading and extracting the latest full node snapshot for ZetaChain. It first ensures lz4 is installed, then fetches snapshot details from an API, downloads the snapshot, and extracts it to the correct directory. Finally, it starts the zetacored service. ```shell # Ensure lz4 is installed sudo apt update && sudo apt install lz4 -y # Capture the JSON response once SNAPSHOT_JSON=$(curl -s https://snapshots.rpc.zetachain.com/mainnet/fullnode/latest.json) # Extract link and filename into variables SNAPSHOT_LINK=$(echo $SNAPSHOT_JSON | jq -r '.snapshots[].link') SNAPSHOT_FILENAME=$(echo $SNAPSHOT_JSON | jq -r '.snapshots[].filename') # Download and extract the snapshot sudo -u zetachain curl "$SNAPSHOT_LINK" -o "/home/zetachain/$SNAPSHOT_FILENAME" && \ sudo -u zetachain lz4 -dc /home/zetachain/$SNAPSHOT_FILENAME | sudo -u zetachain tar -C /home/zetachain/.zetacored/ -xvf - && \ sudo systemctl start zetacored ``` -------------------------------- ### Install Cosmovisor from Precompiled Binary Source: https://www.zetachain.com/docs/nodes/start-here/setup Installs Cosmovisor by downloading a precompiled binary for Linux AMD64 architecture. The downloaded archive is extracted, made executable, and then moved to a system-wide executable path. ```bash wget https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor%2Fv1.7.1/cosmovisor-v1.7.1-linux-amd64.tar.gz tar xf cosmovisor-v1.7.1-linux-amd64.tar.gz &&\ chmod a+x cosmovisor &&\ sudo mv cosmovisor /usr/local/bin ``` -------------------------------- ### Install Current Zetacored Binary Source: https://www.zetachain.com/docs/nodes/start-here/setup Copies the currently installed zetacored binary into the Cosmovisor genesis directory. This ensures Cosmovisor can manage the initial version of the daemon. ```bash sudo -u zetachain cp /usr/local/bin/zetacored /home/zetachain/.zetacored/cosmovisor/genesis/bin ``` -------------------------------- ### Verify Zetacored Installation Source: https://www.zetachain.com/docs/users/cli/setup This snippet demonstrates how to check if the Zetacored command-line interface is installed correctly. Running this command should produce a help message detailing its usage, available commands, and flags. This is a crucial step to ensure the Zetachain node is set up properly. ```bash zetacored ``` -------------------------------- ### Start Zetachain Node Service Source: https://www.zetachain.com/docs/nodes/validate/validator-gcp This set of commands configures and starts the Zetachain node service. It first extracts a snapshot, sets the keyring backend, changes directory ownership, and finally enables and starts the systemd service for zetacored. Dependencies include systemctl and tar. ```bash gsutil cp /var/lib/zetacored/snapshot.tar gs://${gcs_bucket_static}/snapshot/${zetachain_network}/${zetachain_snapshot} fi tar -xf /var/lib/zetacored/snapshot.tar -C /var/lib/zetacored rm /var/lib/zetacored/snapshot.tar # Set the keyring backend. https://docs.cosmos.network/v0.52/user/run-node/keyring /var/lib/zetacored/cosmovisor/genesis/bin/zetacored --home /var/lib/zetacored \ config keyring-backend file # Change the ownership of the directories. chown -R zetachain:zetachain /var/lib/zetacored/config chown -R zetachain:zetachain /var/lib/zetacored/cosmovisor chown -R zetachain:zetachain /var/lib/zetacored/data # Start the Zetachain node. systemctl enable zetacored.service systemctl start zetacored.service ``` -------------------------------- ### Install Go Programming Language Source: https://www.zetachain.com/docs/nodes/validate/validator-gcp This script downloads and installs a specific version of the Go programming language. It removes any previous installation and extracts the new version to /usr/local/go. Dependencies include curl and tar. ```bash #!/bin/bash GO_VERSION="1.20" # Install Go curl -L -O "https://golang.org/dl/go$GO_VERSION.linux-amd64.tar.gz" sudo rm -rf /usr/local/go sudo tar -C /usr/local -xzf "go$GO_VERSION.linux-amd64.tar.gz" rm "go$GO_VERSION.linux-amd64.tar.gz" ``` -------------------------------- ### Switch User for Node Setup Source: https://www.zetachain.com/docs/nodes/validate/validator Switches the current user to the 'zetachain' user, which is necessary for running node-related commands after initial setup. ```bash sudo su -l zetachain ``` -------------------------------- ### Install ZetaChain CLI from Source Source: https://www.zetachain.com/docs/users/cli/setup Instructions to compile the ZetaChain CLI from source code. Requires Go 1.20+ and Git. This method ensures you have the latest version directly from the repository. ```shell git clone https://github.com/zeta-chain/node cd node make install ``` -------------------------------- ### Install Dependencies and Compile Contracts - Yarn & Forge Source: https://www.zetachain.com/docs/developers/standards/token After creating a new token project, these commands install the required project dependencies using Yarn and then compile the Solidity smart contracts using Forge. This prepares the project for deployment. ```bash cd token yarn forge soldeer update forge build ``` -------------------------------- ### Install The Graph CLI Source: https://www.zetachain.com/docs/about/services/the-graph Installs the Graph CLI globally on your machine, which is necessary for initializing, building, and deploying subgraphs. This command uses npm, the Node Package Manager. ```bash npm install -g @graphprotocol/graph-cli ``` -------------------------------- ### Install Dependencies and Compile Universal NFT Contracts Source: https://www.zetachain.com/docs/developers/standards/nft After creating a new project, these commands install the project's dependencies using yarn and update the Solidity dependencies. Finally, forge build compiles the smart contracts, preparing them for deployment. Ensure Forge (Foundry) is installed. ```bash cd nft yarn forge build ``` -------------------------------- ### Install Dependencies and Compile Contracts Source: https://www.zetachain.com/docs/developers/tutorials/messaging After creating the project, these commands install project dependencies, update Solidity compiler configurations, and build the smart contracts. This step is crucial for preparing the project for deployment and testing. ```bash cd messaging yarn forge soldeer update forge build ``` -------------------------------- ### Example Message Encoding (Solidity) Source: https://www.zetachain.com/docs/developers/tutorials/messaging Provides a practical example of encoding a message payload, including a simple string 'hello', a target token, gas limit, and revert options for cross-chain transmission. ```solidity bytes memory data = abi.encode("hello"); bytes memory message = abi.encode( abi.encodePacked(receiver), // Destination contract address (as bytes) targetToken, // Token to transfer on destination chain data, // ABI-encoded message 300_000, // Gas limit revertOptions // Struct specifying fallback behavior ); ``` -------------------------------- ### Install Web3 Name SDK Source: https://www.zetachain.com/docs/about/services/space-id Installs the @web3-name-sdk/core package and viem for interacting with blockchains. For Next.js projects, additional configuration is required to transpile commonjs dependencies. ```bash npm install @web3-name-sdk/core viem@^1.20 ``` -------------------------------- ### Install Zetachain Binary with Fallback Source: https://www.zetachain.com/docs/nodes/validate/validator-gcp This script installs the Zetachain binary, prioritizing Cloud Storage and falling back to GitHub if unavailable. It also copies the binary to the Cosmovisor directories for chain management. Dependencies include gsutil and wget. ```bash #!/bin/bash # Copy the Zetachain binary from Cloud Storage if available. echo "Attempting to download Zetachain binary from Cloud Storage" gsutil cp gs://${gcs_bucket_static}/binaries/${zetacored_version}/zetacored-linux-amd64 /usr/local/bin/zetacored if [ $? -eq 1 ]; then echo "Downloading Zetachain binary from GitHub" wget https://github.com/zeta-chain/node/releases/download/${zetacored_version}/zetacored-linux-amd64 -O /usr/local/bin/zetacored gsutil cp /usr/local/bin/zetacored gs://${gcs_bucket_static}/binaries/${zetacored_version}/zetacored-linux-amd64 fi # Copy the Zetachain client binary to the Cosmovisor directory. mkdir -p /var/lib/zetacored/cosmovisor/genesis/bin mkdir -p /var/lib/zetacored/cosmovisor/upgrades/${zetachain_version}/bin cp /usr/local/bin/zetacored /var/lib/zetacored/cosmovisor/genesis/bin/zetacored cp /usr/local/bin/zetacored /var/lib/zetacored/cosmovisor/upgrades/${zetachain_version}/bin/zetacored chmod a+x /usr/local/bin/zetacored echo "Installed Zetachain binary" ``` -------------------------------- ### Start ZetaChain Localnet with Sui Source: https://www.zetachain.com/docs/developers/tutorials/sui Initiates a local development environment with ZetaChain and Sui running concurrently. This command deploys Gateway contracts on both networks and requires the terminal to remain open. ```bash yarn zetachain localnet start --chains sui ``` -------------------------------- ### Set Up ZetaChain Project with Yarn and Forge Source: https://www.zetachain.com/docs/developers/tutorials/call Initializes a new ZetaChain project using the 'call' template, installs dependencies with Yarn, and updates/builds Solidity contracts with Forge. ```bash zetachain new --project call cd call yarn forge soldeer update forge build ``` -------------------------------- ### ZetaChain CLI Query and Help Commands Source: https://www.zetachain.com/docs/reference/cli Examples of using the ZetaChain CLI to query cross-chain balances and access command-specific help information. These commands are essential for understanding and debugging cross-chain interactions. ```bash zetachain query balances zetachain docs zetachain accounts --help ``` -------------------------------- ### Scaffold ZetaChain Project Source: https://www.zetachain.com/docs/developers/tutorials/frontend Scaffolds a new ZetaChain project named 'hello' using the ZetaChain CLI. This command initializes the project structure and dependencies required for development. ```bash npx zetachain@latest new --project hello cd hello/frontend yarn ``` -------------------------------- ### Initialize ZetaChain Project with CLI Source: https://www.zetachain.com/docs/developers/tutorials/hello Initializes a new ZetaChain project named 'hello' using the ZetaChain CLI. It then navigates into the project directory, installs dependencies using Yarn, and updates Solidity dependencies with Soldeer. ```bash npx zetachain@latest new --project hello cd hello yarn forge soldeer update ``` -------------------------------- ### Launch Localnet Environment Source: https://www.zetachain.com/docs/developers/tutorials/sui-withdraw-and-call This snippet shows how to start the local development environment for ZetaChain and Sui, which includes setting up instances of both blockchains. Keep the terminal open to view deployment details. ```bash npx zetachain localnet start ``` -------------------------------- ### Quick Environment Setup for ZetaChain Staking Source: https://www.zetachain.com/docs/developers/tutorials/staking Sets up environment variables for RPC URL and private key, and demonstrates how to check wallet address and balance using `cast`. It also defines the staking precompile address. ```shell export RPC_URL="https://zetachain-athens-evm.blockpi.network/v1/rpc/public" export PRIVATE_KEY="YOUR_PRIVATE_KEY_HEX" cast wallet address $PRIVATE_KEY cast balance --rpc-url "$RPC_URL" $(cast wallet address $PRIVATE_KEY) export STAKING_PRECOMPILE=0x0000000000000000000000000000000000000800 ``` -------------------------------- ### Create Cosmovisor Directories Source: https://www.zetachain.com/docs/nodes/start-here/setup Sets up the necessary directory structure for Cosmovisor under the Zetachain user's home directory. This includes directories for the genesis binary and future upgrades. ```bash sudo -u zetachain mkdir -p /home/zetachain/.zetacored/cosmovisor/genesis/bin &&\ sudo -u zetachain mkdir -p /home/zetachain/.zetacored/cosmovisor/upgrades ``` -------------------------------- ### Start ZetaChain Localnet using npm Source: https://www.zetachain.com/docs/reference/localnet This command bootstraps the ZetaChain local development environment. It spins up nodes for multiple chains and deploys core ZetaChain protocol contracts, ZRC-20 tokens, and Uniswap pools. ```bash npx zetachain@latest localnet start ``` -------------------------------- ### Install Axios HTTP Client Source: https://www.zetachain.com/docs/about/services/alchemy Installs the axios npm package, which is a popular promise-based HTTP client used for making requests from Node.js or the browser. It will be used to interact with the ZetaChain API. ```shell npm install axios ``` -------------------------------- ### Install ZetaChain Node Binary Source: https://www.zetachain.com/docs/nodes/start-here/setup Downloads the ZetaChain node binary and makes it executable. Ensure you replace 'VERSION' with the latest version and select the correct platform. This binary is essential for running a ZetaChain node. ```bash sudo wget https://github.com/zeta-chain/node/releases/download/VERSION/zetacored-linux-amd64 -O /usr/local/bin/zetacored &&\ sudo chmod a+x /usr/local/bin/zetacored ``` -------------------------------- ### Setup Goldsky CLI for Subgraph Deployment Source: https://www.zetachain.com/docs/about/services/goldsky This section details the steps to set up the Goldsky CLI, authenticate it with an API key, and create a configuration file (`goldsky.json`) for deploying a subgraph. The configuration specifies the contract ABI, the target chain, and the deployed contract instance details. ```bash curl https://goldsky.com | sh goldsky login ``` ```json { "version": "1", "name": "swap", "abis": { "swap": { "path": "artifacts/contracts/Swap.sol/Swap.json" } }, "chains": ["zetachain-testnet"], "instances": [ { "abi": "swap", "address": "0x9846BBdE15B857d88DDad4e00CD76962245E1b6f", "chain": "zetachain-testnet", "startBlock": 3065396 } ] } ``` ```bash goldsky subgraph deploy swap/v1 --from-abi goldsky.json ``` -------------------------------- ### Build and Deploy Example Solana Program Source: https://www.zetachain.com/docs/developers/tutorials/solana This command sequence builds an Anchor-based Solana program and then uses a TypeScript script to deploy it. It requires an environment variable or argument for the SPL-20 USDC address. ```bash cd solana && anchor build && npx ts-node setup/main.ts "$USDC_SPL" && cd - ``` -------------------------------- ### Build Sui Contract (sui move) Source: https://www.zetachain.com/docs/developers/tutorials/sui Builds a Sui smart contract project located in the 'sui' directory. This command compiles the Move code and prepares it for publishing. ```bash sui move build --force ``` -------------------------------- ### Start ZetaChain Localnet with Custom Anvil Flags Source: https://www.zetachain.com/docs/reference/localnet This command starts the ZetaChain local network with specific Anvil flags. It allows customization of block times and gas limits for testing high-throughput contracts or simulating different chain behaviors. Dependencies include `npx` and the ZetaChain CLI. ```bash npx zetachain@latest localnet start \ --anvil "--block-time 1 --gas-limit 120000000" \ --port 9000 ``` -------------------------------- ### Compile Smart Contracts with Foundry Source: https://www.zetachain.com/docs/developers/tutorials/hello This command compiles all Solidity smart contracts within your project using Foundry. It translates human-readable Solidity code into bytecode that the EVM can understand and execute, preparing them for deployment. ```bash forge build ``` -------------------------------- ### Get All Contracts Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves information for all registered contracts. ```APIDOC ## GET /contracts/all ### Description Returns information for all contracts currently registered in the registry. ### Method GET ### Endpoint `/contracts/all` ### Response #### Success Response (200) - **contractsInfo** (ContractInfoDTO[]) - An array of ContractInfoDTO objects, each containing details about a contract. #### Response Example ```json { "contractsInfo": [ { "chainId": 1, "contractType": "ERC20", "address": "0x123...", "is_active": true } ] } ``` ``` -------------------------------- ### Initialize npm Project Source: https://www.zetachain.com/docs/about/services/alchemy Creates a new directory for the project and initializes a Node.js project using npm. This sets up the basic structure for managing project dependencies. ```shell mkdir zetachain-app cd zetachain-app npm init -y ``` -------------------------------- ### Get All ZRC20 Tokens Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves information for all registered ZRC20 tokens. ```APIDOC ## GET /zrc20/all ### Description Returns information for all ZRC20 tokens that are registered in the registry. ### Method GET ### Endpoint `/zrc20/all` ### Response #### Success Response (200) - **tokensInfo** (ZRC20Info[]) - An array of ZRC20Info objects, each containing details about a ZRC20 token. #### Response Example ```json { "tokensInfo": [ { "address": "0xabc...", "symbol": "ZETA", "originChainId": 1, "originAddress": "0x123...", "decimals": 18, "is_active": true } ] } ``` ``` -------------------------------- ### Get All Chains Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves comprehensive information for all chains, both active and inactive. ```APIDOC ## GET /chains/all ### Description Returns detailed information for all chains, including both active and inactive ones, present in the registry. ### Method GET ### Endpoint `/chains/all` ### Response #### Success Response (200) - **chainsInfo** (ChainInfoDTO[]) - An array of ChainInfoDTO objects, each containing information about a specific chain. #### Response Example ```json { "chainsInfo": [ { "chainId": 1, "name": "Ethereum", "is_active": true }, { "chainId": 2, "name": "Polygon", "is_active": false } ] } ``` ``` -------------------------------- ### Get Contract Configuration Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves contract-specific configuration values based on a key. ```APIDOC ## GET /contracts/{chainId}/{contractType}/config/{key} ### Description Gets contract-specific configuration by providing the chain ID, contract type, and configuration key. ### Method GET ### Endpoint `/contracts/{chainId}/{contractType}/config/{key}` ### Parameters #### Path Parameters - **chainId** (uint256) - Required - The ID of the chain where the contract is deployed. - **contractType** (string) - Required - The type of the contract. - **key** (string) - Required - The configuration key to retrieve. ### Response #### Success Response (200) - **value** (bytes) - The value of the requested configuration. #### Response Example ```json { "value": "0xabcdef1234567890" } ``` ``` -------------------------------- ### ZetaChain CLI Project Creation Source: https://www.zetachain.com/docs/reference/cli Details on how to use the `zetachain new` command to create a new universal contract project. It includes command options for specifying output directories and project names. ```bash Usage: zetachain new [options] Create a new universal contract project. Options: --verbose Enable verbose logging --output Specify custom output directory or name --project Specify the example project to use and skip the prompt -h, --help display help for command ``` -------------------------------- ### Get Active Chains Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves a list of all currently active chain IDs in the registry. ```APIDOC ## GET /chains/active ### Description Gets an array of chain IDs for all chains that are currently active in the registry. ### Method GET ### Endpoint `/chains/active` ### Response #### Success Response (200) - **chainIds** (uint256[]) - An array of chain IDs for all active chains. #### Response Example ```json { "chainIds": [1, 5, 7, 10] } ``` ``` -------------------------------- ### Get ZRC20 Token Information Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves detailed information about a specific ZRC20 token. ```APIDOC ## GET /zrc20/{address} ### Description Gets information about a specific ZRC20 token, including its active status, symbol, origin details, and decimals. ### Method GET ### Endpoint `/zrc20/{address}` ### Parameters #### Path Parameters - **address** (address) - Required - The address of the ZRC20 token. ### Response #### Success Response (200) - **active** (bool) - Whether the token is active. - **symbol** (string) - The symbol of the token. - **originChainId** (uint256) - The ID of the foreign chain where the original asset exists. - **originAddress** (bytes) - The address or identifier of the asset on its native chain. - **coinType** (string) - The type of the original coin. - **decimals** (uint8) - The number of decimals the token uses. #### Response Example ```json { "active": true, "symbol": "ZETA", "originChainId": 1, "originAddress": "0xabc123", "coinType": "ETH", "decimals": 18 } ``` ``` -------------------------------- ### Get Contract Information Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves information about a specific contract deployed on a given chain. ```APIDOC ## GET /contracts/{chainId}/{contractType} ### Description Gets information about a specific contract, including its active status and address. ### Method GET ### Endpoint `/contracts/{chainId}/{contractType}` ### Parameters #### Path Parameters - **chainId** (uint256) - Required - The ID of the chain where the contract is deployed. - **contractType** (string) - Required - The type of the contract. ### Response #### Success Response (200) - **active** (bool) - Whether the contract is active. - **addressBytes** (bytes) - The address of the contract. #### Response Example ```json { "active": true, "addressBytes": "0x1234567890abcdef1234567890abcdef12345678" } ``` ``` -------------------------------- ### Publish Sui Contract to Local Instance (sui client) Source: https://www.zetachain.com/docs/developers/tutorials/sui Publishes the compiled Sui smart contract package to the local Sui instance. It skips dependency verification and uses jq to extract the package ID of the published contract. ```bash SUI_CONTRACT=$(sui client publish \ --skip-dependency-verification \ --json 2>/dev/null | jq -r '.objectChanges[] | select(.type == "published") | .packageId') && echo $SUI_CONTRACT ``` -------------------------------- ### Get GatewayZEVM Address (Solidity) Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves the address of the GatewayZEVM contract. This public function returns an address. ```solidity function gatewayZEVM() external returns (address); ``` -------------------------------- ### Get ZetaChain Wallet Address Source: https://www.zetachain.com/docs/nodes/validate/validator-gcp Retrieves the address of a newly created key within the ZetaChain network. This address is used to receive funds. ```bash sudo /var/lib/zetacored/cosmovisor/current/bin/zetacored --home /var/lib/zetacored keys list ``` -------------------------------- ### Initialize a Subgraph Project Source: https://www.zetachain.com/docs/about/services/the-graph Initializes a new subgraph project for The Graph protocol. This command requires your subgraph slug, which is specific to your subgraph created in Subgraph Studio. It guides you through setting up the subgraph's configuration. ```bash graph init --studio ``` -------------------------------- ### Get ZRC20 Address by Foreign Asset Source: https://www.zetachain.com/docs/developers/protocol/evm Finds the ZRC20 token address on ZetaChain corresponding to a foreign asset. ```APIDOC ## GET /zrc20/foreign-asset ### Description Gets the ZRC20 token address on ZetaChain for a given asset on a foreign chain. ### Method GET ### Endpoint `/zrc20/foreign-asset` ### Parameters #### Query Parameters - **originChainId** (uint256) - Required - The ID of the foreign chain. - **originAddress** (bytes) - Required - The address or identifier of the asset on its native chain. ### Response #### Success Response (200) - **zetaChainAddress** (address) - The address of the corresponding ZRC20 token on ZetaChain. #### Response Example ```json { "zetaChainAddress": "0x456def7890abcdef456def7890abcdef456def" } ``` ``` -------------------------------- ### Initiate Swap from Base to Ethereum CLI Source: https://www.zetachain.com/docs/developers/tutorials/swap This command initiates a swap of ETH from the Base Sepolia chain to Ethereum Sepolia via ZetaChain. It utilizes the `deposit-and-call` command with specified chain IDs, amount, and recipient details. The process involves the Base Gateway and ZetaChain's universal swap contract. ```bash npx zetachain evm deposit-and-call \ --chain-id 84532 \ --amount 0.001 \ --types address bytes bool \ --receiver $UNIVERSAL \ --values $ZRC20_ETHEREUM_ETH $RECIPIENT true ``` -------------------------------- ### Create ZetaChain Project with Messaging Template Source: https://www.zetachain.com/docs/developers/tutorials/messaging This command initializes a new ZetaChain project using the 'messaging' template, setting up the necessary files and configurations for cross-chain messaging applications. It requires Node.js and npm/yarn to be installed. ```bash npx zetachain new --project messaging ``` -------------------------------- ### Get All Contracts Information (Solidity) Source: https://www.zetachain.com/docs/developers/protocol/evm Returns an array of ContractInfoDTO structs, providing information for all registered contracts within the system. ```solidity function getAllContracts() external view returns (ContractInfoDTO[] memory contractsInfo); ``` -------------------------------- ### Initialize Gateway and Caps in Move Source: https://www.zetachain.com/docs/developers/protocol/sui Implements the `init` function to set up the initial state of the gateway. It creates and assigns necessary capabilities (WithdrawCap, WhitelistCap, AdminCap) and initializes the Gateway object with default settings, including whitelisting SUI. The function requires a mutable transaction context. ```Move **fun** init(ctx: &**mut** sui::tx_context::TxContext) ``` Implementation ``` **fun** init(ctx: &**mut** TxContext) { // to withdraw tokens from the gateway, the caller must have the WithdrawCap **let** withdraw_cap = WithdrawCap { id: object::new(ctx), }; // to whitelist a new vault, the caller must have the WhitelistCap **let** whitelist_cap = WhitelistCap { id: object::new(ctx), }; // to whitelist a new vault, the caller must have the AdminCap **let** admin_cap = AdminCap { id: object::new(ctx), }; // create and share the gateway object **let** **mut** gateway = Gateway { id: object::new(ctx), vaults: bag::new(ctx), nonce: 0, active_withdraw_cap: object::id(&withdraw_cap), active_whitelist_cap: object::id(&whitelist_cap), deposit_paused: **false**, }; // whitelist SUI by default whitelist_impl(&**mut** gateway, &whitelist_cap); transfer::transfer(withdraw_cap, tx_context::sender(ctx)); transfer::transfer(whitelist_cap, tx_context::sender(ctx)); transfer::transfer(admin_cap, tx_context::sender(ctx)); transfer::share_object(gateway); } ``` ``` -------------------------------- ### Get Active Chains (Solidity) Source: https://www.zetachain.com/docs/developers/protocol/evm Returns an array of chain IDs for all currently active chains in the registry. This function is read-only. ```solidity function getActiveChains() external view returns (uint256[] memory); ``` -------------------------------- ### Fetch ZetaChain Network Configuration Files Source: https://www.zetachain.com/docs/nodes/start-here/setup Downloads essential configuration files (genesis.json, client.toml, config.toml, app.toml) for the ZetaChain node. These files are crucial for connecting to the network and are saved in the node's data directory. ```bash sudo -u zetachain wget https://raw.githubusercontent.com/zeta-chain/network-config/main/mainnet/genesis.json -O /home/zetachain/.zetacored/config/genesis.json &&\ sudo -u zetachain wget https://raw.githubusercontent.com/zeta-chain/network-config/main/mainnet/client.toml -O /home/zetachain/.zetacored/config/client.toml &&\ sudo -u zetachain wget https://raw.githubusercontent.com/zeta-chain/network-config/main/mainnet/config.toml -O /home/zetachain/.zetacored/config/config.toml &&\ sudo -u zetachain wget https://raw.githubusercontent.com/zeta-chain/network-config/main/mainnet/app.toml -O /home/zetachain/.zetacored/config/app.toml ``` -------------------------------- ### Get All ZRC20 Tokens Information (Solidity) Source: https://www.zetachain.com/docs/developers/protocol/evm Retrieves an array of ZRC20Info structs, containing details for all registered ZRC20 tokens in the registry. ```solidity function getAllZRC20Tokens() external view returns (ZRC20Info[] memory tokensInfo); ``` -------------------------------- ### Zetad Service Configuration (Systemd) Source: https://www.zetachain.com/docs/nodes/validate/validator-gcp The systemd service file configuration for 'zetacored', managed by Cosmovisor. It defines how the service starts, restarts, runs under a specific user, and its environment variables. ```systemd [Unit] Description=zetacored (running under Cosmovisor) After=multi-user.target StartLimitIntervalSec=0 [Install] WantedBy=multi-user.target [Service] User=zetachain ExecStart=/usr/local/bin/cosmovisor run start --home /var/lib/zetacored/ --log_format json --moniker ${moniker} Restart=on-failure RestartSec=3 WorkingDirectory=/var/lib/zetacored/cosmovisor Environment="DAEMON_NAME=zetacored" Environment="DAEMON_HOME=/var/lib/zetacored" # Note that downloading binaries is enabled due to relatively short # release timescales for ZetaChain. Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=true" Environment="DAEMON_RESTART_AFTER_UPGRADE=true" Environment="DAEMON_DATA_BACKUP_DIR=/var/lib/zetacored" Environment="UNSAFE_SKIP_BACKUP=true" Type=simple LimitNOFILE=262144 ``` -------------------------------- ### Build and Deploy a Subgraph Source: https://www.zetachain.com/docs/about/services/the-graph Commands to generate code, build the subgraph project, authenticate with Subgraph Studio using a deploy key, and finally deploy the subgraph. A version label is required during the deployment process. ```bash $ graph codegen $ graph build $ graph auth --studio $ graph deploy --studio ``` -------------------------------- ### Get External IPv4 Address Source: https://www.zetachain.com/docs/nodes/start-here/setup Retrieves the external IPv4 address of the machine using the icanhazip.com service. This is useful for setting the external_address in the config.toml file. ```shell curl -4 icanhazip.com ``` -------------------------------- ### Get Gateway Contract Address (Bash) Source: https://www.zetachain.com/docs/developers/tutorials/swap Retrieves the Gateway contract address for the Ethereum chain from the local registry file using `jq`. This is a prerequisite for initiating cross-chain transactions. ```bash GATEWAY_ETHEREUM=$(jq -r '.["11155112"].contracts[] | select(.contractType == "gateway") | .address' ~/.zetachain/localnet/registry.json) && echo $GATEWAY_ETHEREUM ``` -------------------------------- ### Deploy Universal Contract using Foundry Source: https://www.zetachain.com/docs/developers/tutorials/hello This command deploys the Universal contract to the ZetaChain Localnet using Foundry. It specifies the RPC URL, the pre-funded private key, the EVM version, and enables broadcasting. The output includes the deployed contract address. ```bash UNIVERSAL=$(forge create Universal \ --rpc-url http://localhost:8545 \ --private-key $PRIVATE_KEY \ --evm-version paris \ --broadcast \ --json | jq -r .deployedTo) && echo $UNIVERSAL ``` -------------------------------- ### Configure ZetaChain Node DB Backend (TOML) Source: https://www.zetachain.com/docs/nodes/start-here/syncing Modifies the `config.toml` file for a ZetaChain node to set the database backend to `goleveldb`. This is a prerequisite for KSYNC compatibility, as KSYNC currently does not support ZetaChain's default pebbledb. ```toml db_backend = "goleveldb" ``` -------------------------------- ### Get All Chains Information (Solidity) Source: https://www.zetachain.com/docs/developers/protocol/evm Fetches comprehensive information for all registered chains, including both active and inactive ones. Returns an array of ChainInfoDTO structs. ```Solidity function getAllChains() external view returns (ChainInfoDTO[] memory); ```