Oasis Sapphire
Interaction tools
Geth
Interact with your Oasis Sapphire node using Geth.
-
Install Geth.
-
Use
geth attach
command with the node endpoint.geth attach YOUR_CHAINSTACK_ENDPOINT
where YOUR_CHAINSTACK_ENDPOINT — your node HTTPS or WSS endpoint protected either with the key or password. See node access details.
-
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("0x4EA0911033792C93639bEd297B9289E136d86F89"))
MetaMask
On node access details, click Add to MetaMask.
Development tools
Truffle
Configure Truffle Suite to deploy contracts to your Oasis Sapphire nodes.
-
Install Truffle Suite, HD Wallet-enabled Web3 provider, and create a project.
-
Install the sapphire-hardhat plugin.
-
Install the dotenv package to securely load your sensitive variables from a
.env
file -
Create a new environment, and define a new network, in
truffle-config.js
:require('dotenv').config(); const sapphire = require("@oasisprotocol/sapphire-paratime"); const HDWalletProvider = require("@truffle/hdwallet-provider"); module.exports = { networks: { sapphire_testnet: { provider: () => { sapphire.wrap( new HDWalletProvider([process.env.YOUR_PRIVATE_KEY], `${process.env.YOUR_CHAINSTACK_ENDPOINT}`)); }, network_id: 0x5aff, }, }, compilers: { solc: { version: "0.8.13", }, }, };
Hardhat
Configure Hardhat to deploy contracts and interact through your Oasis Sapphire nodes.
-
Install Hardhat and create a project.
-
Install the sapphire-hardhat plugin.
-
Install the dotenv package to securely load your sensitive variables from a
.env
file. -
Create a new environment in
hardhat.config.js
:require("@nomicfoundation/hardhat-toolbox"); require('@oasisprotocol/sapphire-hardhat'); require('dotenv').config(); module.exports = { solidity: "0.8.18", defaultNetwork: "sapphire_testnet", networks: { sapphire_testnet: { url: `${process.env.YOUR_CHAINSTACK_ENDPOINT}`, accounts: [process.env.YOUR_PRIVATE_KEY], chainId: 0x5aff, }, }, };
where
- YOUR_CHAINSTACK_ENDPOINT — your node HTTPS or WSS endpoint protected either with the key or password. See node access details.
- YOUR_PRIVATE_KEY — the private key of the account that you use to deploy the contract
-
Run
npx hardhat run --network sapphire_testnet scripts/deploy.js
, and Hardhat will deploy using Chainstack.
web3.js
Build DApps using web3.js and Oasis Sapphire nodes deployed with Chainstack.
- Install web3.js.
- Connect over HTTP or WebSocket.
HTTPS
Use the HttpProvider
object to connect to your node HTTPS endpoint and get the latest block number:
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('YOUR_CHAINSTACK_ENDPOINT'));
web3.eth.getBlockNumber().then(console.log);
where YOUR_CHAINSTACK_ENDPOINT is your node HTTPS endpoint protected either with the key or password.
WSS
Use the WebsocketProvider
object to connect to your node WSS endpoint and get the latest block number:
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.WebsocketProvider('YOUR_CHAINSTACK_ENDPOINT'));
web3.eth.getBlockNumber().then(console.log);
where YOUR_CHAINSTACK_ENDPOINT is your node WSS endpoint protected either with the key or password.
node.js
You can build a web app to query data using node.js and axios:
const axios = require("axios");
const payload = {
jsonrpc: "2.0",
id: 0,
method: "query",
params: []
};
(async () => {
const response = await axios.post(`YOUR_CHAINSTACK_ENDPOINT`, payload)
console.log(response.data)
})();
where
- YOUR_CHAINSTACK_ENDPOINT — your Chainstack node endpoint protected either with the key or password. See node access details.
query
— your JSON-RPC query. In this case, to get the latest block number.
ethers.js
Build DApps using ethers.js and Oasis Sapphire nodes deployed with Chainstack.
- Install ethers.js.
- Connect over HTTPS or WebSocket. See also EVM node connection: HTTP vs WebSocket.
HTTPS
Use the JsonRpcProvider
object to connect to your node endpoint and get the balance of any address:
const ethers = require('ethers');
const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT ";
const provider = new ethers.JsonRpcProvider(NODE_URL, NETWORK_ID);
const eth_getBalance = async () => {
const balance = await provider.getBalance("ACCOUNT_ADDRESS");
console.log(balance);
};
eth_getBalance()
where
- YOUR_CHAINSTACK_ENDPOINT — your node HTTPS endpoint protected either with the key or password
- NETWORK_ID — Oasis Sapphire network ID:
- Mainnet:
23294
- Testnet:
23295
- Mainnet:
- ACCOUNT_ADDRESS — the Oasis Sapphire account address
WebSocket
Use the WebSocketProvider
object to connect to your node WSS endpoint and get the latest block number:
const ethers = require('ethers');
const NODE_URL = "YOUR_CHAINSTACK_ENDPOINT";
const provider = new ethers.WebSocketProvider(NODE_URL, NETWORK_ID);
const eth_getBalance = async () => {
const balance = await provider.getBalance("ACCOUNT_ADDRESS");
console.log(balance);
};
eth_getBalance()
where
- YOUR_CHAINSTACK_ENDPOINT — your node WSS endpoint endpoint protected either with the key or password
- NETWORK_ID — Oasis Sapphire network ID:
- Mainnet:
23294
- Testnet:
23295
- Mainnet:
- ACCOUNT_ADDRESS — the Oasis Sapphire account address
Remix IDE
To make Remix IDE interact with the network through a zkEVM node deployed with Chainstack:
- Get MetaMask and set it to interact through a Chainstack node. See Oasis Sapphire tooling: MetaMask.
- In Remix IDE, navigate to the Deploy tab. Select Injected Provider - MetaMask in Environment.
This will engage MetaMask and make Remix IDE interact with the network through a Chainstack node.
Updated 12 months ago