Onchain Clients
Ethers.js - Instructions for Connecting to Ink
Ethers.js documentation: https://docs.ethers.org/v6/
To connect to Ink by instantiating a new ethers.js
JsonRpcProvider
object with an RPC URL of Ink's testnet, follow the steps below:
-
Install ethers.js: Ensure you have
ethers.js
v6 installed in your project. If not, you can install it using npm or yarn.npm install ethers@6
or
yarn add ethers@6
-
Instantiate a JsonRpcProvider: Use the following code snippet to create a new
JsonRpcProvider
object with the RPC URL of Ink's testnet.import { ethers } from 'ethers'; const rpcUrl = 'https://rpc-gel-sepolia.inkonchain.com'; const provider = new ethers.JsonRpcProvider(rpcUrl, 763373);
-
Using the Provider: You can now use the
provider
to interact with Ink's testnet. For example, you can fetch the current block number or interact with smart contracts deployed on the testnet.// previous code const blockNumber = await provider.getBlockNumber(); console.log(blockNumber);
Example: Fetching the Current Block Number
The following code snippet demonstrates how to fetch and print the current block number from Ink's testnet:
Viem - Instructions for Connecting to Ink
Viem documentation: https://viem.sh/docs/introduction
-
Install Viem: Ensure you have
viem
installed in your project. If not, you can install it using npm or yarn.npm install viem
or
yarn add viem
-
Instantiate a Public Client: Use the following code snippet to create a new
Public Client
object with the Ink Sepolia testnet.import { createPublicClient, http } from 'viem' import { inkSepolia } from 'viem/chains' const client = createPublicClient({ chain: inkSepolia, transport: http(), })
-
Consuming Actions: You can now interact with Ink's chain! Here we are getting the current block number.
// previous code const blockNumber = await client.getBlockNumber(); console.log(blockNumber);