Hello OneChain
This basic example introduces you to the OneChain TypeScript SDK. The Node.js example mints OCT on a OneChain network and then queries the address to get a sum for the owned OCT. You don't need to use an IDE to complete the example, but one like Microsoft Visual Studio Code helps centralize more advanced projects.
Before you begin
You need an address on a OneChain development network (Devnet, Testnet, local). If you don't already have an address, use the OneChain Client CLI or the OneChain Wallet browser extension to create one.
You also need Node.js and a package manager like pnpm to follow this example, so install them on your system if you haven't already.
Start a project
Using a Terminal or Console, create a folder on your system (hello-sui
in this example) and make
it the working directory.
When you use a package manager to install the necessary packages, it downloads the modules to your
node_modules
folder and adds the references to your package.json
file, creating the file if it
doesn't already exist. For this example, you need only the OneChain TypeScript SDK:
Your package.json
file now has a dependencies section with @onelabs/sui
listed with the package
version number.
Get some OCT for your account
Instead of a 'Hello World' output to your console, this example introduces some OCT to your wallet address. You must be on Devnet, Testnet, or a local network to use a faucet for minting OCT.
Create a new index.js
file in the root of your project with the following code.
Save the file, then use Node.js to run it in your Console or Terminal:
The code imports the requestSuiFromFaucetV1
function from the SDK and calls it to mint OCT for the
provided address. The code also imports SuiClient
to create a new client on the OneChain network that
it uses to query the address and output the amount of OCT the address owns before and after using
the faucet. You can check the total OCT for your address using the OneChain Wallet or OneChain Client CLI.
Faucets on Devnet and Testnet are rate limited. If you run the script too many times, you surpass the limit and must wait to successfully run it again.
You can also use the OneChain Client CLI to perform client calls on a OneChain network.