Prerequisites
- A local Sonr network running. See the Validator Setup Guide for instructions
- Node.js version 16 or higher
- npm or yarn
1. Project Setup
1
2
3
Configure TypeScript
Create atsconfig.json
file in your project root with the following configuration:2. Creating a Wallet
Now, let’s create a new TypeScript file and add the logic to create a new Sonr wallet.1
Create the Main File
Create a new file namedindex.ts
.2
Implement Wallet Creation
Add the following code toindex.ts
to create a new wallet and log its address and mnemonic:Important: In a real application, you must store the mnemonic securely.
Never expose it in client-side code.
3
Run the Script
Execute the script usingts-node
:3. Querying the Blockchain
Let’s query the blockchain to get the balance of our new wallet.1
Get Account Balance
Modify yourindex.ts
file to query the account balance after creating the wallet. You will need to fund this account from the localnet faucet for it to have a balance.2
4. Sending a Transaction
Finally, let’s send a transaction from one account to another.1
Implement Transaction Sending
For this step, you will need two wallets. You can create a second one using the samecreateWallet
method. Ensure both wallets have funds from the localnet faucet.Next Steps
This quickstart has shown you the basics of interacting with the Sonr network using our TypeScript SDK. You can now explore more advanced topics:- Service Registration: Register your application as a trusted service
- UCAN Authorization: Implement capability-based permissions
- Smart Contract Interaction: Call and query smart contracts on the Sonr network