testnet
GitHub

Sending Your First Transaction

quickstart

A step-by-step guide to checking your balance and sending OKRW to another address using ethers.js v6.

1

Set up the provider and signer

Install ethers.js (npm install ethers) and connect to the Maroo testnet RPC. Use a private key from a faucet-funded testnet account; never reuse a mainnet key.
import { JsonRpcProvider, Wallet, formatEther, parseEther } from "ethers";

const provider = new JsonRpcProvider("https://rpc-testnet.maroo.io");
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
2

Check your balance

provider.getBalance returns the balance in aokrw (the base unit, 18 decimals). Format it with formatEther to display in OKRW. Confirm you have enough before sending.
const balanceWei = await provider.getBalance(wallet.address);
console.log(`Balance: ${formatEther(balanceWei)} OKRW`); // e.g. "Balance: 100.0 OKRW"
3

Send the transaction

Use wallet.sendTransaction and convert the human-readable amount with parseEther. The transaction is signed locally and broadcast to the testnet. tx.wait() blocks until it's included in a block.
const tx = await wallet.sendTransaction({
  to: "0xRecipientAddress",
  value: parseEther("1.5"), // 1.5 OKRW
});
console.log(`Sent: ${tx.hash}`);

const receipt = await tx.wait();
console.log(`Mined in block ${receipt!.blockNumber}, status: ${receipt!.status === 1 ? "success" : "failed"}`);
4

Verify on the explorer

Open https://explorer-testnet.maroo.io/tx/<your-hash> to see the transaction details. The recipient's balance should now reflect the transfer.
const recipientBalance = await provider.getBalance("0xRecipientAddress");
console.log(`Recipient balance: ${formatEther(recipientBalance)} OKRW`);
Source: maroo
ESC
Type to search