Post
Share your knowledge.
How to switch from testnetConnection to custom RPC in Sui.js?
I'm working on a project using Sui.js and I need to connect to a custom RPC URL instead of using the default testnetConnection. How can I achieve this? I've seen a lot about connecting via testnetConnection, but I need guidance on using a custom setup for my RPC endpoint.
- Move CLI
Answers
1To switch from using testnetConnection
to a custom RPC URL in @mysten/sui.js
, you should initialize the JsonRpcProvider
with a Connection
object that specifies your custom URL instead. Here's an example of how you can achieve this in your project:
import { Connection, JsonRpcProvider } from '@mysten/sui.js';
const connection = new Connection({
fullnode: 'YOUR_CUSTOM_RPC_URL',
});
const provider = new JsonRpcProvider(connection);
This code snippet sets up a connection to your custom RPC endpoint instead of the default testnet connection. Make sure to replace 'YOUR_CUSTOM_RPC_URL'
with your actual RPC URL.
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.