# Tools

# Interaction tools

# Geth

Interact with your Ethereum node using Geth (opens new window).

  1. Install Geth (opens new window).

  2. Use geth attach command with the node endpoint.

geth attach ENDPOINT

where

  • ENDPOINT — your node HTTPS or WSS endpoint.

See View node access and credentials.

Example:

  • Key-protected
  • Password-protected
geth attach https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d
  1. Invoke any methods from Web3 JavaScript API (opens new window).

Example below demonstrates how to get the balance of an address in wei value and convert it to ether value:

> web3.fromWei(web3.eth.getBalance("0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"))
642538.078574759898951277

# GraphQL

You can use GraphQL on dedicated nodes on the Growth, Business, and Enterprise subscription plans.

# UI

You can query data using the graphical interface.

  1. On Chainstack, navigate to your dedicated Ethereum node. See View node access and credentials.
  2. Hover over GraphQL IDE URL and click Open.
  3. In the graphical interface that opens, run a GraphQL query.

Example to get the latest block number:

{ block { number } }

# Node.js

You can build a web app to query data using Node.js and axios (opens new window):

const axios = require('axios');
const main = async () => {
  try {
    const result = await axios.post(
      'ENDPOINT',
      {
        query: `
          QUERY
        `
      }
    );
    console.log(result.data);
  } catch(error) {
    console.error(error);
  }
}
main();

where

  • ENDPOINT — your node GraphQL endpoint.
  • QUERY — your GraphQL query.

See View node access and credentials.

Example to get the latest block number:

  • Key-protected
  • Password-protected
const axios = require('axios');
const main = async () => {
  try {
    const result = await axios.post(
      'https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d/graphql',
      {
        query: `
          { block { number } }
        `
      }
    );
    console.log(result.data);
  } catch(error) {
    console.error(error);
  }
}
main();

# MetaMask

You can set your MetaMask (opens new window) to interact through your Ethereum nodes deployed with Chainstack.

  1. Open your MetaMask and click the network selector.

  2. In the network selector, click Custom RPC.

  3. In the New RPC URL field, enter the endpoint. See View node access and credentials.

    Example:

    • Key-protected
    • Password-protected
    https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d
    
  4. In the Chain ID field, enter the ID of the network:

    • Mainnet: 1
    • Ropsten: 3
    • Rinkeby: 4
  5. Click Save.

See also View node access and credentials.

# Development tools

# Truffle

Configure Truffle Suite (opens new window) to deploy contracts to your Ethereum nodes.

  1. Install Truffle Suite (opens new window), HD Wallet-enabled Web3 provider (opens new window), and create a project.

  2. Create a new environment in truffle-config.js, add your mnemonic phrase generated by a wallet (opens new window) and the node endpoint:

  • Key-protected
  • Password-protected
onst HDWalletProvider = require("@truffle/hdwallet-provider");
const mnemonic = 'pattern enroll upgrade ...';
...
module.exports = {
 networks: {
    chainstack: {
        provider: () => new HDWalletProvider(mnemonic, "https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d"),
        network_id: "*"
    },
   }
  }
};

# Hardhat

Configure Hardhat (opens new window) to deploy contracts and interact through your Ethereum nodes.

  1. Install Hardhat (opens new window) and create a project.

  2. Create a new environment in hardhat.config.js:

require("@nomiclabs/hardhat-waffle");
...
module.exports = {
  solidity: "0.7.3",
  networks: {
    chainstack: {
        url: "ENDPOINT",
        accounts: ["PRIVATE_KEY"]
    },
   }
};

where

  • ENDPOINT — your node HTTPS or WSS endpoint.
  • PRIVATE_KEY — the private key of the account that you use to deploy the contract.

See also View node access and credentials.

Example:

  • Key-protected
  • Password-protected
require("@nomiclabs/hardhat-waffle");
...
module.exports = {
  solidity: "0.7.3",
  networks: {
    chainstack: {
        url: "https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d",
        accounts: ["ee5dda7d38d194783d32adcfc961401108b8fdde27e8fee115553959d434e68b"]
    },
   }
};
  1. Run npx hardhat run scripts/deploy.js --network chainstack and Hardhat will deploy using Chainstack.

See also Forking EVM-compatible mainnet with Hardhat.

# Embark

Configure Embark (opens new window) to deploy contracts to your Ethereum nodes.

  1. Install Embark (opens new window) and create a project.

  2. Create a new environment in config/contracts.js, add your mnemonic phrase generated by a wallet (opens new window) and the node hostname:

chainstack: {
  deployment:{
    accounts: [
      {
        mnemonic: 'pattern enroll upgrade ...'
      }
    ],
    host: "HOSTNAME",
    port: false,
    protocol: "https",
    type: "rpc"
  }
}

where

  • HOSTNAME — your node HTTPS endpoint hostname with credentials.

See also View node access and credentials.

Example:

  • Key-protected
  • Password-protected
chainstack: {
  deployment:{
    accounts: [
      {
        mnemonic: 'pattern enroll upgrade ...'
      }
    ],
    host: "nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d",
    port: false,
    protocol: "https",
    type: "rpc"
  }
}
  1. Run embark run chainstack and Embark will deploy using Chainstack.

# Remix IDE

To make Remix IDE interact with the network through a Chainstack node:

  1. Get MetaMask (opens new window) and set it to interact through a Chainstack node. See Interacting through MetaMask.
  2. In Remix IDE, navigate to the Deploy tab. Select Injected Web3 in Environment.

This will engage MetaMask and make Remix IDE interact with the network through a Chainstack node.

For a detailed tutorial with Remix IDE, see Trust Fund account on Ethereum.

# web3.js

Build DApps using web3.js (opens new window) and Ethereum nodes deployed with Chainstack.

# HTTP

  1. Install web3.js (opens new window).
  2. Use the HttpProvider object to connect to your node HTTPS endpoint.
const Web3 = require('web3');

const web3 = new Web3(new Web3.providers.HttpProvider('ENDPOINT'));

where

  • ENDPOINT — your node HTTPS endpoint.

Example to get the latest block number:

  • Key-protected
  • Password-protected
const Web3 = require('web3');

const web3 = new Web3(new Web3.providers.HttpProvider('https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d'));

web3.eth.getBlockNumber().then(console.log);

# WebSocket

  1. Use the WebsocketProvider object to connect to your node WSS endpoint.
const Web3 = require('web3');

const web3 = new Web3(new Web3.providers.WebsocketProvider('ENDPOINT'));

where

  • ENDPOINT — your node WSS endpoint.

Example to get the latest block number:

  • Key-protected
  • Password-protected
const Web3 = require('web3');

const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://ws-nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d'));

web3.eth.getBlockNumber().then(console.log);

# web3.py

Build DApps using web3.py (opens new window) and Ethereum nodes deployed with Chainstack.

  1. Install web3.py (opens new window).
  2. Connect over HTTP or WebSocket. See also EVM node connection: HTTP vs WebSocket.

# HTTP

Use the HTTPProvider to connect to your node endpoint.

  • Key-protected
  • Password-protected
from web3 import Web3

web3 = Web3(Web3.HTTPProvider('ENDPOINT'))

where

  • ENDPOINT — your node HTTPS endpoint.
  • HOSTNAME — your node HTTPS endpoint hostname.
  • USERNAME — your node access username.
  • PASSWORD — your node access password.

See also View node access and credentials.

Example to get the latest block number:

  • Key-protected
  • Password-protected
from web3 import Web3

web3 = Web3(Web3.HTTPProvider('https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d'))
print(web3.eth.blockNumber)

# WebSocket

Use the WebsocketProvider object to connect to your node WSS endpoint.

  • Key-protected
  • Password-protected
from web3 import Web3

web3 = Web3(Web3.WebsocketProvider('ENDPOINT'))

where

  • ENDPOINT — your node WSS endpoint.
  • HOSTNAME — your node WSS endpoint hostname.
  • USERNAME — your node access username.
  • PASSWORD — your node access password.

See also View node access and credentials.

Example to get the latest block number:

  • Key-protected
  • Password-protected
from web3 import Web3

web3 = Web3(Web3.WebsocketProvider('wss://ws-nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d'))
print(web3.eth.blockNumber)

# web3j

Build DApps using web3j (opens new window) and Ethereum nodes deployed with Chainstack.

Use the HttpService object to connect to your node endpoint.

Example to get the latest block number:

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);
    }
  }

}

where

  • ENDPOINT — your node HTTPS endpoint.
  • USERNAME — your node access username.
  • PASSWORD — your node access password.

See also the full code on GitHub (opens new window).

# ethers.js

Build DApps using ethers.js (opens new window) and Ethereum nodes deployed with Chainstack.

  1. Install ethers.js (opens new window).
  2. Connect over HTTP or WebSocket. See also EVM node connection: HTTP vs WebSocket.

# HTTP

Use the JsonRpcProvider object to connect to your node endpoint.

  • Key-protected
  • Password-protected
const { ethers } = require("ethers");

var urlInfo = {
    url: 'ENDPOINT'
};
var provider = new ethers.providers.JsonRpcProvider(urlInfo, NETWORK_ID);

where

  • ENDPOINT — your node HTTPS endpoint.
  • USERNAME — your node access username.
  • PASSWORD — your node access password.
  • NETWORK_ID — Ethereum network ID:
    • Mainnet: 1
    • Ropsten: 3
    • Rinkeby: 4

See also View node access and credentials.

Example to get the latest block number on mainnet:

  • Key-protected
  • Password-protected
const { ethers } = require("ethers");

var urlInfo = {
    url: 'https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d'
};
var provider = new ethers.providers.JsonRpcProvider(urlInfo, 1);

provider.getBlockNumber().then(console.log);

# WebSocket

Use the WebSocketProvider object to connect to your node WSS endpoint.

const { ethers } = require("ethers");

const provider = new ethers.providers.WebSocketProvider('ENDPOINT', NETWORK_ID);

where

  • ENDPOINT — your node WSS endpoint.
  • NETWORK_ID — Ethereum network ID:
    • Mainnet: 1
    • Ropsten: 3
    • Rinkeby: 4

See also View node access and credentials.

Example to get the latest block number on mainnet:

  • Key-protected
  • Password-protected
const { ethers } = require("ethers");

const provider = new ethers.providers.WebSocketProvider('wss://ws-nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d', 1);

provider.getBlockNumber().then(console.log);

# Brownie

  1. Install Brownie (opens new window).
  2. Use the brownie networks add command with the node endpoint:
brownie networks add Ethereum ID name="NETWORK_NAME" host=ENDPOINT chainid=NETWORK_ID

where

  • ID — any name that you will use as the network tag to run a deployment. For example, bsc-mainnet.
  • NETWORK_NAME — any name that you want to identify the network by in the list if networks. For example, Mainnet (Chainstack).
  • ENDPOINT — your node HTTPS or WSS endpoint.
  • NETWORK_ID — Ethereum network ID:
    • Mainnet: 1
    • Ropsten: 3
    • Rinkeby: 4

Example to add an Ethereum mainnet node to the list of Brownie networks:

  • Key-protected
  • Password-protected
brownie networks add Ethereum chainstack-mainnet name="Mainnet (Chainstack)" https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531d chainid=1

Example to run the deployment script:

brownie run deploy.py --network chainstack-mainnet