### Install Chainstack with Example Storage Class Source: https://docs.chainstack.com/docs/self-hosted/installation An example of running the `cpctl install` command, specifying `topolvm-provisioner` as the storage class. ```bash cpctl install -s topolvm-provisioner ``` -------------------------------- ### Get Filter Changes with web3.js Source: https://docs.chainstack.com/reference/arbitrum-getfilterchanges This example shows how to retrieve filter changes using web3.js. You need to have web3.js installed and a web3 instance connected to your Arbitrum node. ```javascript const Web3 = require('web3'); // Replace with your Chainstack Arbitrum RPC endpoint const web3 = new Web3('YOUR_ARBITRUM_RPC_ENDPOINT'); async function getFilterChangesWeb3(filterId) { try { const logs = await web3.eth.getFilterChanges(filterId); console.log('New logs:', logs); return logs; } catch (error) { console.error('Error fetching filter changes:', error); return []; } } // Example usage: Replace '0x123...' with an actual filter ID obtained from eth_newFilter // getFilterChangesWeb3('0x123...'); ``` -------------------------------- ### Set up Project Directory and Virtual Environment Source: https://docs.chainstack.com/docs/plasma-tutorial-monitor-usdt-flows-with-web3py Create a new directory for your project, navigate into it, and set up a Python virtual environment. Install necessary libraries like web3.py and python-dotenv. ```bash mkdir plasma-usdt-monitor cd plasma-usdt-monitor python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install web3 python-dotenv ``` -------------------------------- ### Get AVAX Balance with AvalancheJS Source: https://docs.chainstack.com/docs/avalanche-tooling Example using AvalancheJS to fetch the AVAX balance of a specific address on the X-Chain. Ensure AvalancheJS is installed and configured with your node details. ```javascript import { Avalanche } from "../../dist" import { AVMAPI } from "../../dist/apis/avm" const ip: string = "nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d" // const port: number = 9650 const protocol: string = "https" const networkID: number = 1 const avalanche: Avalanche = new Avalanche(ip, null, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const main = async (): Promise => { const address: string = "X-avax1k30tskunzxr2tmapy8p4y0ujn2802yr3743679" const balance: object = await xchain.getBalance(address, "AVAX") console.log(balance) } main() ``` -------------------------------- ### Hyperliquid Getting Started Source: https://docs.chainstack.com/changelog/chainstack-updates-april-6-2020 Documentation for getting started with the Hyperliquid platform. ```APIDOC ## Hyperliquid Getting Started ### Description This guide provides the initial steps and information required to begin using the Hyperliquid platform. ### Endpoint `reference/hyperliquid-getting-started` ``` -------------------------------- ### Initialize Web3 and Describe Network Source: https://docs.chainstack.com/docs/plasma-tutorial-monitor-usdt-flows-with-web3py Sets up a web3 instance and prints network details. Ensure you have a running Ethereum node or use a service like Chainstack. ```python def main(): w3 = make_web3() describe_network(w3) print("\nRecent USDT transfers:\\n") for transfer in fetch_transfers(w3): print( f"- Block {transfer.block_number} | {transfer.amount:,.6f}" ``` -------------------------------- ### Set up MetaMask, Hardhat, Foundry, and ethers.js for Oasis Sapphire Source: https://docs.chainstack.com/docs/oasis-sapphire-tooling Instructions for setting up common development tools for building on Oasis Sapphire. ```bash npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-ethers ethers @oasis-open/sapphire-hardhat npx hardhat init ``` -------------------------------- ### Get Ethereum Account Balance with ethers.js Source: https://docs.chainstack.com/reference/ethereum-getbalance This ethers.js example demonstrates how to use the ChainstackProvider to fetch an Ethereum account's balance and convert it from Wei to Ether. Ensure you have ethers.js installed. ```javascript const ethers = require("ethers"); // Create a ChainstackProvider instance for Ethereum mainnet const chainstack = new ethers.ChainstackProvider("mainnet"); const getBalance = async (address, block) => { const balanceHex = await chainstack.send("eth_getBalance", [address, block]); // Convert hex to decimal const balanceDecimal = parseInt(balanceHex, 16); // Convert wei to ether const balanceEther = ethers.formatEther(BigInt(balanceDecimal), "ether"); console.log(balanceEther); }; getBalance("0xCb6Ed7E78d27FDff28127F9CbD61d861F09a2324", "latest"); ``` -------------------------------- ### Create and Navigate to Project Directory Source: https://docs.chainstack.com/docs/ton-how-to-develop-non-fungible-tokens Set up a new directory for your TON NFT project and move into it. This is the first step in project initialization. ```bash mkdir ton-nft-project cd ton-nft-project ``` -------------------------------- ### Python Asyncio Example for Web3 Requests Source: https://docs.chainstack.com/docs/mastering-multithreading-in-python-for-web3-requests-a-comprehensive-guide This snippet demonstrates how to use asyncio and aiohttp to make concurrent Web3 requests. It includes setup for starting and running the main asynchronous function. ```python import asyncio import time import aiohttp async def get_balance_at_block(session, address, block_number): url = f"https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID" payload = { "method": "eth_getBalance", "params": [address, hex(block_number)], "id": 1, "jsonrpc": "2.0" } async with session.post(url, json=payload) as response: result = await response.json() return block_number, result['result'] async def main(): address = "0xYourEthereumAddress" start_block = 18000000 end_block = 18000100 num_blocks = end_block - start_block + 1 async with aiohttp.ClientSession() as session: tasks = [] for i in range(num_blocks): block_num = start_block + i task = asyncio.create_task(get_balance_at_block(session, address, block_num)) tasks.append(task) results = await asyncio.gather(*tasks) results.sort() for block_num, balance in results: print(f"Block: {block_num}, Balance: {balance}") start = time.time() loop.run_until_complete(main()) print(f"Time taken: {time.time() - start}") ``` -------------------------------- ### Initialize Project with PyTONLib Source: https://docs.chainstack.com/docs/ton-tooling Sets up a new Python project and activates a virtual environment. Ensure Python 3.6.0 or higher is installed. ```bash mkdir new-project cd new-project python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate ``` -------------------------------- ### Get Latest Block Number with web3j Source: https://docs.chainstack.com/docs/arbitrum-tooling Connect to an Arbitrum node using web3j and retrieve the latest block number. This Java example includes basic HTTP authentication setup for password-protected endpoints. ```java package getLatestBlock; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import org.web3j.protocol.Web3j; import org.web3j.protocol.core.DefaultBlockParameterName; import org.web3j.protocol.core.methods.response.EthBlock; import org.web3j.protocol.exceptions.ClientConnectionException; import org.web3j.protocol.http.HttpService; import okhttp3.Authenticator; import okhttp3.Credentials; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okhttp3.Route; public final class App { private static final String USERNAME = "USERNAME"; private static final String PASSWORD = "PASSWORD"; private static final String ENDPOINT = "ENDPOINT"; public static void main(String[] args) { try { OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); clientBuilder.authenticator(new Authenticator() { @Override public Request authenticate(Route route, Response response) throws IOException { String credential = Credentials.basic(USERNAME, PASSWORD); return response.request().newBuilder().header("Authorization", credential).build(); } }); HttpService service = new HttpService(RPC_ENDPOINT, clientBuilder.build(), false); Web3j web3 = Web3j.build(service); EthBlock.Block latestBlock = web3.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send().getBlock(); System.out.println("Latest Block: #" + latestBlock.getNumber()); } catch (IOException | ClientConnectionException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); } } } ``` -------------------------------- ### Install with Custom Values Source: https://docs.chainstack.com/docs/self-hosted/advanced-installation Run the installer using your customized values file. Replace `STORAGE_CLASS_NAME` with your actual storage class. ```bash cpctl install -f cp-values.yaml -s STORAGE_CLASS_NAME ``` -------------------------------- ### Get Transaction by Hash using web3.js Source: https://docs.chainstack.com/reference/fantom-gettransactionbyhash This example demonstrates how to fetch transaction details on the Fantom network using web3.js. You need to have web3.js installed and a web3 instance connected to your Chainstack Fantom RPC endpoint. ```javascript const Web3 = require('web3'); // Replace with your Chainstack Fantom RPC endpoint const web3 = new Web3('YOUR_CHAINSTACK_FANTOM_RPC_ENDPOINT'); async function getTransactionByHash(txHash) { try { const transaction = await web3.eth.getTransaction(txHash); console.log('Transaction:', transaction); return transaction; } catch (error) { console.error('Error fetching transaction:', error); return null; } } // Replace with the transaction hash you want to query const transactionHash = '0x...'; getTransactionByHash(transactionHash); ```