Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
Zilliqa 2.0
https://github.com/zilliqa/zq2
Admin
Zilliqa 2.0 code base
Tokens:
176,806
Snippets:
1,007
Trust Score:
9.5
License:
Apache-2.0
Update:
4 months ago
Context
Chat
Benchmark
0.5
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Get Smart Contract Init with Python Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getsmartcontractinit.doc.md This Python example uses the pyzil library to get the initialization parameters of a Zilliqa smart contract. It first sets the active chain to MainNet and then calls the GetSmartContractInit method. ```python from pyzil.zilliqa import chain chain.set_active_chain(chain.MainNet) print(chain.active_chain.api.GetSmartContractInit("fe001824823b12b58708bf24edd94d8b5e1cfcf7")) ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/zilliqa/zq2/blob/main/evm_scilla_js_tests/README.md Install project dependencies and run various test configurations using Hardhat. This includes setup, parallel execution, network-specific tests, and logging options. ```bash npm install npx hardhat setup # to run setup wizard npx hardhat test # to run tests npx hardhat test --parallel # to run tests in parallel mode npx hardhat test --network devnet # to run tests against the devnet npx hardhat test --log-jsonrpc # to run tests and print JSON-RPC requests/responses npx hardhat test --log-txnid # to run tests and print transaction ids. DEBUG=true npx hardhat test # to run tests and print log messages. .env file can be used as well. npx hardhat test --grep something # to run tests containing `something` in the description npx hardhat test filename # to run tests of `filename` npx hardhat test folder/* # to run tests of `folder` npx hardhat test test/scilla/* # to run scilla tests only SCILLA=false npx hardhat test # to disable scilla tests. .env file can be used as well. MOCHA_TIMEOUT=300000 npx hardhat test # To increase mocha timeout. MOCHA_REPORTER=MOCHA_REPORTER=./BriefMochaReporter.ts npx hardhat test # To use brief reporter. ``` -------------------------------- ### Get Minimum Gas Price using Python Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getminimumgasprice.doc.md This Python example uses the pyzil library to get the minimum gas price from the Zilliqa mainnet. Ensure pyzil is installed and configured. ```python from pyzil.zilliqa import chain chain.set_active_chain(chain.MainNet) print(chain.active_chain.api.GetMinimumGasPrice()) ``` -------------------------------- ### Get Blockchain Info using Go Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getblockchaininfo.doc.md Fetch blockchain details using the Go SDK. This example demonstrates creating a provider and marshaling the JSON response. ```go func GetBlockchainInfo() { provider := NewProvider("{{_api_url}}") response := provider.GetBlockchainInfo() result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Go Example Request Source: https://github.com/zilliqa/zq2/blob/main/z2/resources/api.tera.md Example of how to make a request to the API using Go. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { resp, err := http.Get("http://localhost:4242/api/v1/blocks/100") if err != nil { fmt.Println("Error making request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Install svm-rs for Solidity Compilation Source: https://github.com/zilliqa/zq2/blob/main/README.md Installs the svm-rs tool, which is required for compiling Solidity code within the testing environment. After installation, use 'svm install <solc version>' to get a specific Solc version. ```bash cargo install svm-rs ``` -------------------------------- ### Get Balance using Node.js Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getbalance.doc.md This Node.js example demonstrates how to fetch an account's balance using the zilliqa SDK. The balance is returned in the smallest accounting unit, Qa. ```javascript const balance = await zilliqa.blockchain.getBalance( "1eefc4f453539e5ee732b49eb4792b268c2f3908" ); console.log(balance.result); ``` -------------------------------- ### Zilliqa 2 Deployer Configuration File Example Source: https://github.com/zilliqa/zq2/blob/main/z2/docs/deployer.md A minimal YAML configuration file for a ZQ2 network, defining its name, chain ID, node roles, and component versions. Use this as a starting point for your network deployments. ```yaml name: zq2-testnet eth_chain_id: 33103 roles: - bootstrap - validator - api - apps - opsnode - private-api versions: zq2: v0.10.0 ``` -------------------------------- ### Install Dependencies Source: https://github.com/zilliqa/zq2/blob/main/z2/docs/local-network.md Installs necessary dependencies like mitmproxy and npm using apt. ```bash sudo apt install mitmproxy npm ``` -------------------------------- ### Get Transaction Bodies for a Block (Go) Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/gettxnbodiesfortxblock.doc.md This Go example demonstrates how to fetch transaction bodies for a given block using a Zilliqa API provider. ```go func GetTxnBodiesForTxBlock() { provider := NewProvider("{{ _api_url }}") response := provider.GetTxnBodiesForTxBlock("1") result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Get Smart Contract State using Go Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getsmartcontractstate.doc.md A Go example demonstrating how to retrieve smart contract state. It uses a provider to make the API call and marshals the response to JSON. ```go func GetSmartContractState() { provider := NewProvider("{{ _api_url }}") response := provider.GetSmartContractState("fe001824823b12b58708bf24edd94d8b5e1cfcf7") result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Get Recent Transactions using Go Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getrecenttransactions.doc.md This Go code example shows how to use a NewProvider to connect to the Zilliqa API and fetch recent transactions, then marshals the response into a JSON string for printing. ```go func GetRecentTransactions() { provider := NewProvider("{{ _api_url }}") response := provider.GetRecentTransactions() result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Rust Example Request Source: https://github.com/zilliqa/zq2/blob/main/z2/resources/api.tera.md Example of how to make a request to the API using Rust. ```rust use reqwest; use tokio; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let response = reqwest::get("http://localhost:4242/api/v1/blocks/100") .await?; let body = response.text().await?; println!("{}", body); Ok(()) } ``` -------------------------------- ### Install ZQ2 Network Source: https://github.com/zilliqa/zq2/blob/main/z2/docs/deployer.md Installs a ZQ2 network using the specified configuration file. Supports parallel installation and specifies URLs for persistence and checkpoint files. ```bash z2 deployer install --max-parallel 10 --persistence-url gs://my-bucket/persistence.tar zq2-testnet.yaml ``` -------------------------------- ### Java Example Request Source: https://github.com/zilliqa/zq2/blob/main/z2/resources/api.tera.md Example of how to make a request to the API using Java. ```java OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("http://localhost:4242/api/v1/blocks/100") .get() .build(); client.newCall(request).execute(); ``` -------------------------------- ### Install Dependencies Source: https://github.com/zilliqa/zq2/blob/main/scripts/zilliqa_api_comparator/README.md Installs the necessary Python packages for the Zilliqa API Comparator using the provided requirements file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install a new network Source: https://github.com/zilliqa/zq2/blob/main/z2/docs/deployer.md Command to install a new Zilliqa network. Requires a prepared YAML configuration file. ```bash z2 deployer install <config.yaml> ``` -------------------------------- ### Node.js Example Request Source: https://github.com/zilliqa/zq2/blob/main/z2/resources/api.tera.md Example of how to make a request to the API using Node.js. ```javascript const fetch = require('node-fetch'); fetch('http://localhost:4242/api/v1/blocks/100', { method: 'GET' }).then(response => { return response.json(); }).then(data => { console.log(data); }); ``` -------------------------------- ### Python Example Request Source: https://github.com/zilliqa/zq2/blob/main/z2/resources/api.tera.md Example of how to make a request to the API using Python. ```python import requests response = requests.get('http://localhost:4242/api/v1/blocks/100') print(response.json()) ``` -------------------------------- ### Setup Network and Run Tests Source: https://github.com/zilliqa/zq2/blob/main/evm_scilla_js_tests/README.md Set up a specific network for testing and then run tests against it. The setup command generates signers for the network. ```bash npx hardhat setup --network <network_name> #If --network is not specified, the default one will be used. In our config, the default network is isolated_server ``` ```bash npx hardhat test --network <network_name> ``` ```bash npx hardhat test --parallel --network <network_name> ``` -------------------------------- ### Start Node with Private Key and Checkpoint Source: https://github.com/zilliqa/zq2/blob/main/z2/docs/join.md Executes the generated startup script to run the node, using an exported private key and an optional checkpoint file. ```bash chmod +x /path/to/zq2/start_node.sh /path/to/zq2/start_node.sh -k $PRIVATE_KEY -p <checkpoint_file.ckpt> # Use .dat for versions prior to v0.19.0 ``` -------------------------------- ### Example: Generate Genesis Key Source: https://github.com/zilliqa/zq2/blob/main/infra/ansible/README.md Example command to generate the genesis key for the Zilliqa network, specifying the project ID and path to the network configuration YAML file. ```bash python3 scripts/generate_genesis_key.py --project-id prj-d-zq2-devnet-c83bkpsd ../../zq2-infratest.yaml ``` -------------------------------- ### Admin Get Peers API Response Example Source: https://github.com/zilliqa/zq2/blob/main/docs/api/admin/admin_getPeers.doc.md This is an example of a successful response from the admin_getPeers endpoint, detailing swarm and sync peers. ```json { "jsonrpc": "2.0", "id": 1, "result": { "swarm_peers": [ "12D3KooWBmwkafWE9JFWqFBe7tBXm1Q4t6R2nV4p8J3xQ5m7L9kS", "12D3KooWCrMTaGRNkpqXeQBrv4RqP8Kd2wNmH5xY7zA9BcEfGhIj" ], "sync_peers": [ "12D3KooWDxMnP7qR8sKfWe5YnT4vBcDfGhIjK3L9mNpQ2rStUvWx" ] } } ``` -------------------------------- ### Get Transaction Bodies for a Block (Java) Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/gettxnbodiesfortxblock.doc.md This Java example shows how to call the Zilliqa API to get transaction bodies for a specific block using an HTTP client. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<List<List<String>>> transactionList = client.getTxnBodiesForTxBlock("2"); System.out.println(new Gson().toJson(transactionList)); } } ``` -------------------------------- ### GetStateProof using Go Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getstateproof.doc.md Illustrates how to retrieve state proof in Go using a provider. This example requires setting up a provider with your API URL and then calling the GetStateProof method. ```go func GetStateProof() { provider := NewProvider("{{ _api_url }}") response, _ := provider.GetStateProof("6d84363526a2d764835f8cf52dfeefe80a360fac", "A0BD91DE66D97E6930118179BA4F1836C366C4CB3309A6B354D26F52ABB2AAC6","39") result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Get Balance using Python Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getbalance.doc.md This Python example uses the pyzil library to get the balance of a Zilliqa account. Ensure you set the active chain to MainNet before calling the API. ```python from pyzil.zilliqa import chain chain.set_active_chain(chain.MainNet) print(chain.active_chain.api.GetBalance("1eefc4f453539e5ee732b49eb4792b268c2f3908")) ``` -------------------------------- ### Example: Generate Private Keys Source: https://github.com/zilliqa/zq2/blob/main/infra/ansible/README.md Example command to generate private keys for Zilliqa nodes, specifying the project ID and path to the network configuration YAML file. ```bash python3 scripts/generate_private_keys.py --project-id prj-d-zq2-devnet-c83bkpsd ../../zq2-infratest.yaml ``` -------------------------------- ### Example: Generate Stats Key Source: https://github.com/zilliqa/zq2/blob/main/infra/ansible/README.md Example command to generate the stats dashboard key, specifying the project ID and path to the network configuration YAML file. ```bash python3 scripts/generate_stats_key.py --project-id prj-d-zq2-devnet-c83bkpsd ../../zq2-infratest.yaml ``` -------------------------------- ### Get Network ID using Python (Active Chain) Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getnetworkid.doc.md This Python example shows how to get the network ID by first setting the active chain to MainNet using the pyzil library, then accessing the API. ```python from pyzil.zilliqa import chain from pyzil.zilliqa.api import ZilliqaAPI # EITHER chain.set_active_chain(chain.MainNet) network_id = chain.active_chain.api.GetNetworkId() print(network_id) ``` -------------------------------- ### Get Blockchain Info using Node.js Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getblockchaininfo.doc.md Fetch blockchain information using the Zilliqa JavaScript SDK. Ensure the SDK is installed and configured. ```javascript const blockChainInfo = await zilliqa.blockchain.getBlockChainInfo(); console.log(blockChainInfo.result); ``` -------------------------------- ### Setting Up Test Environment and Running Hardhat Tests Source: https://github.com/zilliqa/zq2/blob/main/evm_scilla_js_tests/README.z2.md Source the generated environment script and execute Hardhat tests to interact with the Zilliqa network. ```bash $ source /my/dir/test_env.sh $ npx hardhat test ``` -------------------------------- ### Run Zilliqa Node with Private Key and Config Source: https://github.com/zilliqa/zq2/blob/main/README.md Starts a Zilliqa node using a provided private key and a configuration file. Ensure the private key is valid and the config file path is correct. ```bash cargo run --bin zilliqa -- 65d7f4da9bedc8fb79cbf6722342960bbdfb9759bc0d9e3fb4989e831ccbc227 -c ./infra/config_docker.toml ``` ```bash cargo run --bin zilliqa -- 62070b1a3b5b30236e43b4f1bfd617e1af7474635558314d46127a708b9d302e -c ./infra/config_rpc_disabled.toml ``` ```bash cargo run --bin zilliqa -- 56d7a450d75c6ba2706ef71da6ca80143ec4971add9c44d7d129a12fa7d3a364 -c ./infra/config_rpc_disabled.toml ``` ```bash cargo run --bin zilliqa -- db670cbff28f4b15297d03fafdab8f5303d68b7591bd59e31eaef215dd0f246a -c ./infra/config_rpc_disabled.toml ``` -------------------------------- ### Get Transaction Rate using Java Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/gettransactionrate.doc.md This Java example shows how to obtain the transaction rate via an HTTP provider. The response is then serialized to JSON. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<Integer> transactionRate = client.getTransactionRate(); System.out.println(new Gson().toJson(transactionRate)); } } ``` -------------------------------- ### Get Block by Hash (Curl) Source: https://github.com/zilliqa/zq2/blob/main/docs/api/eth/eth_getBlockByHash.doc.md Example of how to call the eth_getBlockByHash method using curl. Ensure the Content-Type is set to application/json and the request method is POST. ```sh curl -d '{ "id": "1", "jsonrpc": "2.0", "method": "eth_getBlockByHash", "params": [ "0x50b3b76c3a4f19ac20e498744d8e0ff9a110b9130acb3ba786c80c26738ee9ae", true ] }' -H "Content-Type: application/json" -X POST "{{ _api_url }}" ``` -------------------------------- ### Generate Node Startup Script and Configuration for Testnet Source: https://github.com/zilliqa/zq2/blob/main/z2/docs/join.md Generates the node startup scripts and configuration file for joining the zq2-testnet. ```bash z2 join --chain zq2-testnet āļø Generating the node startup scripts and configuration š Chain specification: zq2-testnet š¤ Role: Node š¾ Node config: /path/to/zq2/zq2-testnet.toml š¾ Startup script: /path/to/zq2/start_node.sh ``` -------------------------------- ### Bootstrap Zilliqa Network with Docker Compose Source: https://github.com/zilliqa/zq2/blob/main/README.md Automates the setup of a 4-node Zilliqa 2.0 network using Docker Compose. This is useful for quick local development and testing. ```bash docker-compose up ``` -------------------------------- ### Get Blockchain Info using Java Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getblockchaininfo.doc.md Retrieve blockchain statistics with the Zilliqa Java SDK. This example uses HttpProvider and Gson for JSON parsing. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<BlockchainInfo> blockchainInfo = client.getBlockchainInfo(); System.out.println(new Gson().toJson(blockchainInfo)); } } ``` -------------------------------- ### Get Smart Contracts with Java SDK Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getsmartcontracts.doc.md Example of retrieving smart contract addresses using the Java SDK. This requires setting up the HttpProvider with the API URL. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<List<Contract>> smartContracts = client.getSmartContracts("fe001824823b12b58708bf24edd94d8b5e1cfcf7"); System.out.println(new Gson().toJson(smartContracts)); } } ``` -------------------------------- ### Get Prev DS Difficulty using Java Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getprevdsdifficulty.doc.md Provides a Java example for fetching the previous DS difficulty. It utilizes an HttpProvider to interact with the Zilliqa API. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<Integer> prevDSDifficulty = client.getPrevDSDifficulty(); System.out.println(new Gson().toJson(prevDSDifficulty)); } } ``` -------------------------------- ### Get Smart Contract Init with Java Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getsmartcontractinit.doc.md This Java code shows how to fetch smart contract initialization parameters using the Zilliqa Java SDK. It requires setting up an HttpProvider with the API URL and then calling the getSmartContractInit method. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<List<Contract.State>> smartContractInit = client.getSmartContractInit("fe001824823b12b58708bf24edd94d8b5e1cfcf7"); System.out.println(new Gson().toJson(smartContractInit)); } } ``` -------------------------------- ### Sample Pre-configured Rules Configuration Source: https://github.com/zilliqa/zq2/blob/main/infra/tf/modules/google-cloud-armor/README.md Illustrates how to define multiple pre-configured WAF rules, including options for including specific rule IDs and detailed exclusion configurations. ```HCL pre_configured_rules = { "php-stable_level_1_with_include" = { action = "deny(502)" priority = 3 description = "PHP Sensitivity Level 1 with included rules" target_rule_set = "xss-v33-stable" sensitivity_level = 0 include_target_rule_ids = ["owasp-crs-v030301-id933190-php", "owasp-crs-v030301-id933111-php"] } "sqli_sensitivity_level_4" = { action = "deny(502)" priority = 1 target_rule_set = "sqli-v33-stable" sensitivity_level = 4 preconfigured_waf_config_exclusions = { exclusion_1 = { target_rule_set = "sqli-v33-stable" target_rule_ids = ["owasp-crs-v030301-id942120-sqli", "owasp-crs-v030301-id942130-sqli"] request_cookie = [ { operator = "STARTS_WITH" value = "abc" } ] request_header = [ { operator = "STARTS_WITH" value = "xyz" }, { operator = "STARTS_WITH" value = "uvw" } ] } exclusion_2 = { target_rule_set = "sqli-v33-stable" target_rule_ids = ["owasp-crs-v030301-id942150-sqli", "owasp-crs-v030301-id942180-sqli"] request_header = [ { operator = "STARTS_WITH" value = "lmn" }, { operator = "ENDS_WITH" value = "opq" } ] request_uri = [ { operator = "CONTAINS" value = "https://hashicorp.com" }, { operator = "CONTAINS" value = "https://xyz.com" }, ] } } } } ``` -------------------------------- ### Get Network ID using Python (Direct API) Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getnetworkid.doc.md This Python example demonstrates fetching the network ID by directly initializing ZilliqaAPI with the endpoint URL. ```python from pyzil.zilliqa import chain from pyzil.zilliqa.api import ZilliqaAPI # OR new_api = ZilliqaAPI(endpoint="{{ _api_url }}") network_id = new_api.GetNetworkId() print(network_id) ``` -------------------------------- ### Get Transactions for a Transaction Block (Go) Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/gettransactionsfortxblock.doc.md Retrieve Zilliqa block transactions using the Go SDK. This example initializes the provider and prints the marshalled JSON response. ```go import ( "encoding/json" "fmt" "provider" ) func GetTransactionsForTxBlock() { provider := NewProvider("{{ _api_url }}") response := provider.GetTransactionsForTxBlock("1") result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Create and Send Zilliqa Transaction in Go Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/createtransaction.doc.md This Go function demonstrates the process of creating a new wallet, adding a private key, setting up a provider, constructing a transaction object, signing it, and sending it to the Zilliqa network. It also shows how to handle the response and confirm the transaction. ```go func SendTransaction() { wallet := NewWallet() wallet.AddByPrivateKey("e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930") provider := provider2.NewProvider("{{_api_url}}") tx := &transaction.Transaction{ Version: strconv.FormatInt(int64(util.Pack(1, 1)), 10), SenderPubKey: "0246E7178DC8253201101E18FD6F6EB9972451D121FC57AA2A06DD5C111E58DC6A", ToAddr: "4BAF5faDA8e5Db92C3d3242618c5B47133AE003C", Amount: "10000000", GasPrice: "2000000000", GasLimit: "50", Code: "", Data: "", Priority: false, } err := wallet.Sign(tx, *provider) if err != nil { fmt.Println(err) } rsp := provider.CreateTransaction(tx.ToTransactionPayload()) if rsp.Error != nil { fmt.Println(rsp.Error) } else { result := rsp.Result.(map[string]interface{}) hash := result["TranID"].(string) fmt.Printf("hash is %s\n", hash) tx.Confirm(hash, 1000, 3, provider) } } ``` -------------------------------- ### Get Transactions for a Transaction Block (Java) Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/gettransactionsfortxblock.doc.md Retrieve transactions from a Zilliqa block using the Java SDK. This example demonstrates setting up the HTTP provider and calling the API. ```java import com.google.gson.Gson; import io.zilliqa.api.HttpProvider; import io.zilliqa.entity.Rep; import java.io.IOException; import java.util.List; public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<List<List<String>>> transactionList = client.getTransactionsForTxBlock("2"); System.out.println(new Gson().toJson(transactionList)); } } ``` -------------------------------- ### Get Smart Contracts with Node.js SDK Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getsmartcontracts.doc.md This Node.js snippet demonstrates how to use the Zilliqa SDK to fetch smart contract addresses. Ensure the SDK is installed and configured. ```javascript const smartContracts = await zilliqa.blockchain.getSmartContracts( "1eefc4f453539e5ee732b49eb4792b268c2f3908" ); console.log(smartContracts.result); ``` -------------------------------- ### Get Transaction Count with Java Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getnumtxnstxepoch.doc.md This Java example demonstrates how to fetch the transaction count from the Zilliqa API using an HTTP provider. The response is printed as a JSON string. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<String> numTxnsTxEpoch = client.getNumTxnsTxEpoch(); System.out.println(new Gson().toJson(numTxnsTxEpoch)); } } ``` -------------------------------- ### Get Smart Contract Init with Go Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getsmartcontractinit.doc.md This Go code snippet demonstrates how to retrieve smart contract initialization parameters using the Zilliqa Go SDK. It initializes a provider with the API URL and calls the GetSmartContractInit method. ```go func GetSmartContractInit() { provider := NewProvider("{{ _api_url }}") response := provider.GetSmartContractInit("fe001824823b12b58708bf24edd94d8b5e1cfcf7") result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Build and Run Local z2 Network Source: https://github.com/zilliqa/zq2/blob/main/z2/docs/local-network.md Builds the zq2 project and then runs a local Zilliqa 2 network, creating configuration in the specified directory. ```bash cargo build ./scripts/z2 run /tmp/some_dir ``` -------------------------------- ### Get Total Coin Supply using Go Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/gettotalcoinsupply.doc.md Retrieve the total coin supply using the Go SDK. This example demonstrates creating a provider and calling the `GetTotalCoinSupply` method. ```go func GetTotalCoinSupply() { provider := NewProvider("{{ _api_url }}") response := provider.GetTotalCoinSupply() result, _ := json.Marshal(response) fmt.Println(string(result)) } ``` -------------------------------- ### Get Latest DS Block using Java Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/getlatestdsblock.doc.md Provides a Java example for fetching the latest DS block. It uses an HttpProvider to make the request and Gson to format the output. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<DsBlock> dsBlock = client.getLatestDsBlock(); System.out.println(new Gson().toJson(dsBlock)); } } ``` -------------------------------- ### Start State Migration Configuration Source: https://github.com/zilliqa/zq2/blob/main/docs/state_migration.md Configure your node to load a specific checkpoint and enable state synchronization for migration. ```toml [[nodes]] load_checkpoint.hash = "14ec8508b34b93fe35d07d885acac51edef2c7ac6660e2f20d97e1cee4fa704c" load_checkpoint.file = "/data/014169600.ckpt" db.state_sync = true ``` -------------------------------- ### Set up GCP Authentication Source: https://github.com/zilliqa/zq2/blob/main/infra/ansible/README.md Configures Google Cloud SDK for authentication and sets the default project. Replace <your-project-id> with your actual GCP project ID. ```bash gcloud auth application-default login gcloud config set project <your-project-id> ``` -------------------------------- ### Example Response for web3_ClientVersion Source: https://github.com/zilliqa/zq2/blob/main/docs/api/web3/web3_clientVersion.doc.md This is an example of a successful response when querying the client version. The result field indicates the node's name and version. ```json { "id": "1", "jsonrpc": "2.0", "result": "zilliqa2/v2.0.0" } ``` -------------------------------- ### Get Transaction Block Rate using Java Source: https://github.com/zilliqa/zq2/blob/main/docs/api/zilliqa/gettxblockrate.doc.md This Java code example shows how to obtain the transaction block rate from the Zilliqa API using an HttpProvider. The response is then serialized to JSON. ```java public class App { public static void main(String[] args) throws IOException { HttpProvider client = new HttpProvider("{{ _api_url }}"); Rep<Double> txBlockRate = client.getTxBlockRate(); System.out.println(new Gson().toJson(txBlockRate)); } } ```