Developers
Create a Wallet
Create a BitSong wallet programmatically using CosmJS for the Crescendo-1 testnet.
CosmJS is the official JavaScript/TypeScript library for interacting with Cosmos SDK chains. Use it to create wallets, sign transactions, and query the chain programmatically.
Set Up CosmJS
Install dependencies
npm install @cosmjs/proto-signing @cosmjs/stargate
The latest version is 0.38.x.
Generate a new wallet
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
const wallet = await DirectSecp256k1HdWallet.generate(24, {
prefix: "bitsong"
})
const [account] = await wallet.getAccounts()
console.log("Address:", account.address)
console.log("Mnemonic:", wallet.mnemonic)
Store the mnemonic securely. Never commit it to source control or expose it in client-side code in production.
Recover a wallet from mnemonic
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
"your twenty four word mnemonic phrase goes here ...",
{ prefix: "bitsong" }
)
const [account] = await wallet.getAccounts()
console.log("Address:", account.address)
Connect to the testnet and query balance
import { StargateClient } from "@cosmjs/stargate"
const rpcEndpoint = "https://rpc.testnet.bitsong.io"
const client = await StargateClient.connect(rpcEndpoint)
const address = "bitsong1youraddresshere"
const balance = await client.getBalance(address, "ubtsg")
console.log("Balance:", balance.amount, balance.denom)
1000000 ubtsg = 1 BTSG. The ubtsg denomination uses 6 decimal places.