waves-da-sdk
v0.12.2
Published
Dapp Abstraction (DA) SDK for Waves
Readme
waves-da-sdk
JavaScript/TypeScript SDK for using DA Wallets on Waves blockchain.
Installation
npm i waves-da-sdkQuick Start
Step 1: Check if user has a DA wallet
Before anything else, check if the user already has a DA wallet registered.
import { getActiveDAOrNull } from "waves-da-sdk";
const da = await getActiveDAOrNull(nodeUrl, {
registry: "3N...", // Registry address (see waves-da.com)
eoa: userAddress // User's EOA address
});
if (!da) {
// User doesn't have a DA wallet yet
// Option A: Redirect to waves-da.com to create one
// Option B: Integrate creation into your app (see next section)
} else {
// DA wallet exists, proceed with authentication + relayer
}Step 2 (Option B): Create DA wallet in your app
If you want users to create their DA wallet directly in your app, here's how to do it as 4 separate user actions:
Step 2.1: Generate and display the DA account
User clicks "Generate DA Wallet" button:
import { randomSeed, address, publicKey } from "@waves/ts-lib-crypto";
// Generate a new DA account (client-side only)
const daSeed = randomSeed(15);
const daAddress = address({ publicKey: publicKey(daSeed) }, chainId);
// Display to user: "Save this seed securely"
console.log("DA Address:", daAddress);
console.log("DA Seed:", daSeed); // ⚠️ User must save this!Step 2.2: Fund the DA account
User clicks "Fund DA Account" button and specifies the amount:
import { Signer } from "@waves/signer";
import { ProviderKeeper } from "@waves/provider-keeper";
// Initialize signer (Waves browser wallet integration)
const signer = new Signer({ NODE_URL: "https://nodes-testnet.wavesnodes.com" });
signer.setProvider(new ProviderKeeper());
// User specifies amount they want to fund
const fundAmount = userInput.amount; // e.g., 3_000_000
// Transfer funds from user wallet to DA address
await signer.transfer({
amount: fundAmount,
recipient: daAddress
}).broadcast();
console.log("DA account funded with:", fundAmount);Step 2.3: Deploy DA smart contract
User clicks "Deploy DA Contract" button:
import { broadcast, waitForTx } from "@waves/waves-transactions";
import { compileDaScript, buildDeployDATx, DA_RIDE_SOURCE } from "waves-da-sdk";
// Compile DA script on the node
const compiled = await compileDaScript(nodeUrl, DA_RIDE_SOURCE);
// Build deployment transaction (requires DA seed from Step 2.1)
const deployTx = buildDeployDATx(
{ chainId, fee: 1_400_000, compiledScript: compiled },
daSeed // From Step 2.1
);
// Broadcast and wait for confirmation
await waitForTx((await broadcast(deployTx, nodeUrl)).id, { apiBase: nodeUrl });
console.log("DA contract deployed at:", daAddress);Step 2.4: Register in Registry
User clicks "Register DA Wallet" button (requires wallet signature):
import { Signer } from "@waves/signer";
import { ProviderKeeper } from "@waves/provider-keeper";
const signer = new Signer({ NODE_URL: nodeUrl });
signer.setProvider(new ProviderKeeper());
// Sign and broadcast registration transaction
const registryAddress = "3N..."; // Your Registry contract address
await signer.invoke({
dApp: daAddress, // The DA contract
call: {
function: "initAndRegister",
args: [{ type: "string", value: registryAddress }],
},
payment: [],
}).broadcast();
console.log("DA wallet registered! Ready to use.");Step 3: Authenticate user with relayer
User is now ready to use the relayer. Authenticate once:
import { RelayerAuthClient, RelayerSession } from "waves-da-sdk";
import { Signer } from "@waves/signer";
import { ProviderKeeper } from "@waves/provider-keeper";
const signer = new Signer({ NODE_URL: "https://nodes-testnet.wavesnodes.com" });
signer.setProvider(new ProviderKeeper());
const authClient = new RelayerAuthClient("http://localhost:3000");
const session = new RelayerSession();
// One-step authentication: login + relayer authorization
// Token is automatically stored and reused
const auth = await authClient.loginAndAuthenticate(signer, session);Step 4: Call your dApp via relayer
Now you can invoke dApp functions using the DA wallet. All Waves callable argument types are supported:
const response = await fetch("http://localhost:3000/invoke", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${auth.token}`,
},
body: JSON.stringify({
eoa: auth.eoa,
targetDapp: "3YourDApp...",
function: "deposit",
args: [
1000000, // Int
"memo", // String
true, // Boolean
{ binary: "AQID" }, // ByteVector (base64)
{ list: ["tag1", "tag2", "tag3"] }, // List[String]
{ list: [10, 20, 30] }, // List[Int]
],
payments: [{ amount: 500000 }],
}),
});
const result = await response.json();
console.log("Transaction ID:", result.txId);Arg types summary:
| Waves type | JSON | SDK (TypeScript) |
|------------|------|-----------------|
| Int | 42 | 42 |
| String | "hello" | "hello" |
| Boolean | true | true |
| ByteVector | { "binary": "base64..." } | new Uint8Array(...) |
| List[...] | { "list": [...] } | [...] (nested array) |
API Reference
Registry
| Function | Returns | Usage |
|----------|---------|-------|
| getActiveDAOrNull(nodeUrl, {registry, eoa}) | ActiveDA \| null | Get user's DA wallet, or null if none |
| getActiveDA(nodeUrl, {registry, eoa}) | ActiveDA | Same as above, throws error if no DA |
DA Wallet Creation
| Function | Usage |
|----------|-------|
| compileDaScript(nodeUrl, source) | Compile DA script on the blockchain node |
| buildDeployDATx(params, daSeed) | Build deployment transaction |
| buildSetPendingOwnerDataTx(params, daSeed) | Set EOA as contract owner |
| DA_RIDE_SOURCE | Ride source code of DA contract |
Relayer Authentication
| Class | Method | Usage |
|-------|--------|-------|
| RelayerAuthClient | loginAndAuthenticate(signer, session) | One-step login + relayer auth |
| RelayerSession | isValid() / getToken() / clear() | JWT token management |
Types
| Type | Description |
|------|-------------|
| ActiveDA | { da: string; daPubKey: string } |
| RegistryInfo | { registry: string; eoa: string } |
Full Documentation
- Integration guide: waves-da.com/docs
- Registry addresses: waves-da.com/registry
- Relayer setup: See
README.mdin waves-da-relayer
