Run nodes on Chainstack
Start for free and get your app to production levels immediately. No credit card required. You can sign up with your GitHub, X, Google, or Microsoft account.
Wallets
Wallets allow the addition of custom RPC endpoints either by directly modifying the settings of an existing network (e.g., Ethereum) or by adding a custom network and specifying a custom RPC endpoint.
To obtain the address of your RPC endpoint, navigate to the node details on the Chainstack console and locate the Execution client HTTPS endpoint in the Access and credentials section. When adding a new network, you need a chain ID which you can on resources like chainlist.org or chainlist.wtf.
In the section Access and credentials of a Chainstack Node, press Add to MetaMask. This will prompt you to confirm a new network details.
To add a network manually, go to Networks and add a new network with a required chain ID and your Chainstack RPC endpoint.
Trust Wallet
To add a custom RPC to Trust Wallet, open the wallet and navigate to the Settings section. Look for the Network section to add a custom network with your Chainstack RPC endpoint.
Rainbow
To add a custom RPC to Rainbow Wallet, open the wallet and navigate to the Settings section. Look for the Networks to add your Chainstack RPC endpoint.
Rabby
To add a custom RPC to Rabby Wallet, open the wallet and navigate to the Settings (More) section. Look for the Modify RPC URL to add your Chainstack RPC endpoint.
Frame Desktop
To add a custom RPC to Frame Desktop, open the wallet and navigate to the Chains section. Click on the chain details to add your Chainstack RPC endpoint.
IDEs
Cloud-based IDEs provide the flexibility to use injected providers. MetaMask is the most commonly used one. By adding a Chainstack RPC node in MetaMask and connecting to the wallet in your IDE, you can seamlessly interact with the network throught a Chainstack node.
Remix IDE
To enable Remix IDE to interact with the network through a Chainstack node, you can follow these steps:
- Install and set up MetaMask to use a Chainstack node for interaction. You can refer to the guide on Interacting through MetaMask for detailed instructions.
- Open Remix IDE and go to the Deploy tab (or Deploy and run transactions tab). Here, select Injected Provider - MetaMask as your environment.
ChainIDE
To enable Remix IDE to interact with the network through a Chainstack node, you can follow these steps:
- Install and set up MetaMask to use a Chainstack node for interaction. You can refer to the guide on Interacting through MetaMask for detailed instructions.
- Open ChainIDE and navigate the Connect Wallet button. Here, select Injected Web3 Provider and then MetaMask.
Programming languages and libraries
Communication protocols
WebSockets and HTTP are essential communication protocols in web applications. WebSockets enable two-way, persistent communication between a client and a server, useful for real-time price feeds, live transaction monitoring, and event notifications. In contrast, HTTP follows a one-way, request-response model, ideal for retrieving periodic price updates and transaction histories.
web3.js
Build DApps using web3.js and Ethereum nodes deployed with Chainstack.
Initialize HTTP or WebSocket provider
import { Web3, HttpProvider, WebSocketProvider } from 'web3';
// Using HTTP provider
const httpProvider = new Web3(new HttpProvider("/*YOUR_HTTP_CHAINSTACK_ENDPOINT*/"));
httpProvider.eth.getBlockNumber().then(console.log);
// Using WebSocket provider
const wsProvider = new Web3(new WebSocketProvider("/*YOUR_WS_CHAINSTACK_ENDPOINT*/"));
wsProvider.eth.getBlockNumber().then((blockNumber) => {
console.log(blockNumber);
wsProvider.currentProvider.safeDisconnect();
});
ethers.js
Build DApps using ethers.js and Ethereum nodes deployed with Chainstack.
Initialize HTTP or WebSocket provider
import { ethers } from 'ethers';
// Using HTTP provider
const httpProvider = new ethers.JsonRpcProvider("/*YOUR_HTTP_CHAINSTACK_ENDPOINT*/");
httpProvider.getBlockNumber().then(console.log);
// Using WebSocket provider
const wsProvider = new ethers.WebSocketProvider("/*YOUR_WS_CHAINSTACK_ENDPOINT*/");
wsProvider.getBlockNumber().then((blockNumber) => {
console.log(blockNumber);
wsProvider.destroy();
});
web3.py
Build DApps using web3.py and Ethereum nodes deployed with Chainstack.
Initialize HTTP or WebSocket provider
from web3 import Web3
# Using HTTP provider
http_web3 = Web3(Web3.HTTPProvider("/*YOUR_HTTP_CHAINSTACK_ENDPOINT*/"))
print(http_web3.eth.block_number)
# Using WebSocket provider
with Web3(Web3.WebsocketProvider("/*YOUR_WS_CHAINSTACK_ENDPOINT*/")) as ws_web3:
print(ws_web3.eth.block_number)
Nethereum (.NET)
Build DApps using Nethereum and Ethereum nodes deployed with Chainstack.
Initialize HTTP or WebSocket provider
using Nethereum.JsonRpc.WebSocketClient;
using Nethereum.Web3;
namespace TutorialWeb3
{
internal class Program
{
static void Main(string[] args)
{
// Using HTTP provider
var httpClient = new Web3("/*YOUR_HTTP_CHAINSTACK_ENDPOINT*/");
var httpBlockNumber = httpClient.Eth.Blocks.GetBlockNumber.SendRequestAsync().GetAwaiter().GetResult();
Console.WriteLine($"HTTP Block Number: {httpBlockNumber}");
// Using WebSocket provider
using (var wsClient = new WebSocketClient("/*YOUR_WS_CHAINSTACK_ENDPOINT*/"))
{
var web3Ws = new Web3(wsClient);
var wsBlockNumber = web3Ws.Eth.Blocks.GetBlockNumber.SendRequestAsync().GetAwaiter().GetResult();
Console.WriteLine("WS Block Number: " + wsBlockNumber);
}
}
}
}
viem
Build DApps using viem and Ethereum nodes deployed with Chainstack.
Initialize HTTP or WebSocket provider
import { createPublicClient, http, webSocket } from 'viem';
import { mainnet } from 'viem/chains';
// Using HTTP provider
const httpClient = createPublicClient({
chain: mainnet,
transport: http("/*YOUR_HTTP_CHAINSTACK_ENDPOINT*/"),
});
const blockNumber = await httpClient.getBlockNumber();
console.log(blockNumber);
// Using WebSocket provider
const wsClient = createPublicClient({
chain: mainnet,
transport: webSocket("/*YOUR_WS_CHAINSTACK_ENDPOINT*/"),
})
const wsBlockNumber = await wsClient.getBlockNumber();
console.log(wsBlockNumber);
await wsClient.transport.getRpcClient().then((rpcClient) => {
rpcClient.close();
});
Chainstack subgraphs (GraphQL)
GraphQL can be utilized on Chainstack Subgraphs to query indexed blockchain data. You can deploy your own subgraph or use subgraphs, already deployed subgraphs for major DeFi applications. There are multiple tools and libraries available for that. Please check our tutorials on subgraphs.
Foundry
Configure Foundry to deploy contracts using Chainstack Ethereum nodes.
Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup
Configure environment in Foundry
Create a new Foundry project:
forge init my_project
cd my_project
Create a .env
file in your project root and add your Chainstack endpoint and private key:
CHAINSTACK_MAINNET_ENDPOINT=https://your-chainstack-mainnet-url
CHAINSTACK_DEVNET_ENDPOINT=https://your-chainstack-devnet-url
PRIVATE_KEY_MAINNET=your-mainnet-private-key
PRIVATE_KEY_DEVNET=your-devnet-private-key
You need to load the environment variables into your shell session:
source .env
echo $CHAINSTACK_DEVNET_URL
echo $PRIVATE_KEY_DEVNET
Update your foundry.toml
file to include the Chainstack network:
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
[rpc_endpoints]
mainnet = "${CHAINSTACK_MAINNET_URL}"
devnet = "${CHAINSTACK_DEVNET_URL}"
Before deploying, ensure that your contracts are compiled. This step is crucial to avoid deployment issues.
To use the Chainstack endpoint for deployment, you can use the following command:
forge create --rpc-url ${CHAINSTACK_DEVNET_URL} --private-key ${PRIVATE_KEY_DEVNET} src/YourContract.sol:YourContract
Alternatively, you can create a deployment script in the script
folder, for example Deploy.s.sol
:
// script/Deploy.s.sol
// Specify the Solidity version
pragma solidity ^0.8.20;
// Import the Forge script library
import "forge-std/Script.sol";
// Import your contract
import "../src/YourContract.sol";
contract DeployScript is Script {
function run() external {
// Retrieve the deployer's private key from the environment variables
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_DEVNET"); // Change to PRIVATE_KEY_MAINNET for mainnet
// Start broadcasting transactions using the deployer's private key
vm.startBroadcast(deployerPrivateKey);
// Deploy the contract
YourContract yourContract = new YourContract();
// Stop broadcasting transactions
vm.stopBroadcast();
// Log the deployed contract address
console2.log("Contract deployed at:", address(yourContract));
}
}
Then run the script with:
forge script script/Deploy.s.sol:DeployScript --rpc-url devnet--broadcast
Interact with the blockchain using Cast. Use the following command to query the balance of an Ethereum address:
cast balance <ETH_ADDRESS> --rpc-url $CHAINSTACK_RPC_URL
Replace <ETH_ADDRESS> with the actual Ethereum address you want to query.
Hardhat
Configure Hardhat to deploy contracts using Chainstack Ethereum nodes.
Install Hardhat and other dependencies
npm init -y
npm install --save-dev hardhat @nomiclabs/hardhat-ethers ethers dotenv
Configure environment in Hardhat
Create a .env
file in your project root and add your Chainstack endpoint and private key:
CHAINSTACK_MAINNET_ENDPOINT=https://your-chainstack-mainnet-url
CHAINSTACK_DEVNET_ENDPOINT=https://your-chainstack-devnet-url
PRIVATE_KEY_MAINNET=your-mainnet-private-key
PRIVATE_KEY_DEVNET=your-devnet-private-key
Initiate a project:
Update your hardhat.config.js
file to use the Chainstack endpoint:
require('@nomiclabs/hardhat-ethers');
require('dotenv').config();
module.exports = {
solidity: "0.8.20", // Specify the required compiler version
networks: {
mainnet: {
url: process.env.CHAINSTACK_MAINNET_ENDPOINT,
accounts: [process.env.PRIVATE_KEY_MAINNET] // Mainnet private key
},
devnet: {
url: process.env.CHAINSTACK_DEVNET_ENDPOINT,
accounts: [process.env.PRIVATE_KEY_DEVNET] // Devnet private key
}
}
};
To deploy your contracts using the Chainstack endpoint, you can create a deployment script in the `scripts` folder, for example deploy.js:
const hre = require("hardhat");
async function main() {
// Retrieve the deployer account from the list of signers
const [deployer] = await hre.ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
// Load the contract factory from the contracts folder
const Token = await hre.ethers.getContractFactory("MyToken"); // Replace "MyToken" with your contract name
// Specify the initial supply for the token (adjust as necessary)
const initialSupply = hre.ethers.utils.parseUnits("1000", 18); // Adjust the supply and decimals as needed
// Deploy the contract and wait for it to be mined
const token = await Token.deploy(initialSupply);
await token.deployed();
// Output the contract address and transaction hash once deployed
console.log("Contract deployed at address:", token.address);
console.log("Transaction hash:", token.deployTransaction.hash);
}
// Execute the main function and handle potential errors
main()
.then(() => process.exit(0))
.catch((error) => {
console.error("Error during deployment:", error);
process.exit(1);
});
Use the appropriate network flag (mainnet or devnet) to deploy to the respective network
npx hardhat run scripts/deploy.js --network devnet
Scaffold-ETH 2
Configure Scaffold-ETH 2 to deploy contracts using Chainstack Ethereum nodes.
Clone the Scaffold-ETH 2 repository
git clone https://github.com/scaffold-eth/scaffold-eth-2.git
cd scaffold-eth-2
Create a .env.local file in the root directory of your project
Add your Chainstack endpoint and private key to the .env.local file
CHAINSTACK_MAINNET_ENDPOINT=https://your-chainstack-mainnet-url
CHAINSTACK_DEVNET_ENDPOINT=https://your-chainstack-devnet-url
DEPLOYER_PRIVATE_KEY=your-private-key-here
Note: by default, Scaffold-ETH 2 uses Alchemy RPC nodes and it assumes the config contains an Alchemy API key. We can override this setting Chainstack RPC nodes and updating some other configs.
Modify the packages/hardhat/hardhat.config.ts file to configure the Chainstack endpoint. Locate the networks section and add or modify the configuration for the Chainstack networks
const config: HardhatUserConfig = {
solidity: "0.8.20", // Ensure to specify the correct Solidity version
networks: {
mainnet: {
url: process.env.CHAINSTACK_MAINNET_ENDPOINT || `https://eth-mainnet.alchemyapi.io/v2/${providerApiKey}`, // Use the Chainstack mainnet endpoint
// accounts: [process.env.DEPLOYER_PRIVATE_KEY_MAINNET as string], // Mainnet private key
},
sepolia: {
url: process.env.CHAINSTACK_DEVNET_ENDPOINT || `https://eth-sepolia.g.alchemy.com/v2/${providerApiKey}`, // Use the Chainstack devnet endpoint
// accounts: [process.env.DEPLOYER_PRIVATE_KEY_DEVNET as string], // Devnet private key
},
// ... other network configurations
},
};
Compile contracts using Hardhat
cd packages/hardhat
yarn hardhat compile
To deploy your contracts using the Chainstack endpoint, run
yarn deploy --network sepolia
To start the NextJS app with the Chainstack configuration
Truffle (no longer maintained)
Configure Truffle to deploy contracts using Chainstack Ethereum nodes.
Install Truffle and other dependencies
# Initialize a new npm project
npm init -y
# Install Truffle as a local development dependency
npm install --save-dev truffle @truffle/hdwallet-provider dotenv
Configure environment in Truffle
Initialize a new Truffle project:
Create a .env
file in your project root and add your Chainstack endpoint and private key:
CHAINSTACK_MAINNET_ENDPOINT=https://your-chainstack-mainnet-url
CHAINSTACK_DEVNET_ENDPOINT=https://your-chainstack-devnet-url
PRIVATE_KEY_MAINNET=your-mainnet-private-key
PRIVATE_KEY_DEVNET=your-devnet-private-key
Update your truffle-config.js
file to use the Chainstack endpoint:
require('dotenv').config();
const HDWalletProvider = require('@truffle/hdwallet-provider');
module.exports = {
networks: {
// Configuration for Mainnet
mainnet: {
provider: () => new HDWalletProvider(process.env.PRIVATE_KEY_MAINNET, process.env.CHAINSTACK_MAINNET_ENDPOINT),
network_id: 1, // Mainnet's network ID
},
// Configuration for Devnet
devnet: {
provider: () => new HDWalletProvider(process.env.PRIVATE_KEY_DEVNET, process.env.CHAINSTACK_DEVNET_ENDPOINT),
network_id: 11155111, // Sepolia
},
},
compilers: {
solc: {
version: "0.8.20", // Specify the Solidity compiler version
},
},
};
Create a migration script in the migrations folder to deploy your contract (migrations/1_deploy_contract_name.js)
// Import your contract artifact
const YourContract = artifacts.require("CONTRACT_NAME");
module.exports = function (deployer) {
deployer.YourContract();
};
To deploy your contract using the Chainstack endpoint, run
truffle migrate --network devnet
Ape
Configure Ape Framework to deploy contracts using Chainstack Ethereum nodes. Before performing the following steps, you can set up and activate a virtual environment.
Install Ape and dependencies
Configure environment in Ape
Initialize a project:
Create or update your ape-config.yaml
file in your project root:
name: ape-1
contracts_folder: contracts # Default is contracts
default_ecosystem: ethereum # Default is ethereum
node:
ethereum:
mainnet:
uri: CHAINSTACK_MAINNET_ENDPOINT
sepolia:
uri: CHAINSTACK_SEPOLIA_ENDPOINT
dependencies:
- name: OpenZeppelin
github: OpenZeppelin/openzeppelin-contracts/token/ERC20/ERC20.sol # Example
version: 4.4.2
Import an account. You’ll be prompted to enter a private key and pass phrase to encrypt it.
ape accounts import devnet_deployer
To deploy your contracts using the Chainstack endpoint, you can create a deployment script, for example scripts/deploy.py
from ape import accounts, project
def main():
# Load the account for deployment
# Change 'devnet_deployer' to 'mainnet_deployer' when deploying to mainnet
account = accounts.load("devnet_deployer")
# Deploy the contract
contract = account.deploy(project.MyContract) # Replace 'MyContract' with your contract's name and add its arguments
# Output the contract address
print(f"Contract deployed at: {contract.address}")
# Output the transaction hash
print(f"Transaction hash: {contract.txn_hash.hex()}")
if __name__ == "__main__":
main()
Compile contracts. Before deploying, ensure your contracts are compiled. Ape automatically compiles contracts when deploying, but you can manually compile them if needed
Run the deployment script using
ape run scripts/deploy.py --network ethereum:sepolia
Brownie (no longer maintained)
Configure Brownie to deploy contracts using Chainstack Ethereum nodes.
Create a Python virtual environment and install Brownie
python -m venv venv
source venv/bin/activate # On Windows, use venv\Scripts\activate
pip install eth-brownie
Configure environment in Brownie
Create a new Brownie project (add --force
if a folder is not empty):
In your project directory, create a .env
file and add your Chainstack endpoint and private key:
CHAINSTACK_MAINNET_ENDPOINT=https://your-chainstack-mainnet-url
CHAINSTACK_DEVNET_ENDPOINT=https://your-chainstack-devnet-url
PRIVATE_KEY_MAINNET=your-mainnet-private-key
PRIVATE_KEY_DEVNET=your-devnet-private-key
Ensure that your terminal session loads these environment variables. You can manually source the .env file:
Update the brownie-config.yaml
file in your project root:
dotenv: .env
networks:
default: development
chainstack-mainnet:
host: ${CHAINSTACK_MAINNET_ENDPOINT}
chainid: 1
explorer: https://etherscan.io
chainstack-devnet:
host: ${CHAINSTACK_DEVNET_ENDPOINT}
chainid: 1337 # Example chain ID for devnet; adjust if different
Add a custom network to Brownie’s network list:
brownie networks add Ethereum chainstack-mainnet host=${CHAINSTACK_MAINNET_ENDPOINT} chainid=1
brownie networks add Ethereum chainstack-devnet host=${CHAINSTACK_DEVNET_ENDPOINT} chainid=1337
To use your private key for deployments, you can create a scripts/deploy.py
file:
import os
from brownie import accounts, Counter # Replace 'Counter' with your contract's class name
def main():
# Load the deployer's account using the private key from the environment variable
acct = accounts.add(os.getenv("PRIVATE_KEY_DEVNET")) # Use PRIVATE_KEY_MAINNET for mainnet
# Deploy the contract (Replace 'Counter' with the actual name of your contract)
contract = Counter.deploy({'from': acct})
# Output the contract address and transaction hash
print(f"Contract deployed at: {contract.address}")
print(f"Transaction hash: {contract.tx.txid}")
To deploy your contracts using the Chainstack endpoint, run
brownie run scripts/deploy.py --network chainstack-devnet