SDK Overview
Build applications on RP1 using our official SDKs.
Available SDKs
| SDK | Language | Status | Package |
|---|---|---|---|
| TypeScript SDK | TypeScript/JavaScript | Stable | @rp1/sdk |
| Python SDK | Python | Coming Soon | rp1-sdk |
| Go SDK | Go | Coming Soon | github.com/rp1-network/rp1-sdk-go |
| Rust SDK | Rust | Coming Soon | rp1-sdk |
TypeScript SDK
The primary SDK for web and Node.js applications.
Install
npm install @rp1/sdk
# or
yarn add @rp1/sdk
# or
pnpm add @rp1/sdk
Quick Example
import { RP1Client, Wallet } from '@rp1/sdk';
// Connect to network
const client = new RP1Client('https://rpc.rp.one');
// Create wallet from mnemonic
const wallet = Wallet.fromMnemonic('your mnemonic phrase...');
// Get balance
const balance = await client.getBalance(wallet.address, 'urp1');
console.log(`Balance: ${balance.amount} urp1`);
// Send tokens
const tx = await client.send({
from: wallet.address,
to: 'rp1recipient...',
amount: '1000000',
denom: 'urp1',
});
console.log(`TX Hash: ${tx.hash}`);
SDK Architecture
┌─────────────────────────────────────────────────────────────┐
│ Your Application │
├─────────────────────────────────────────────────────────────┤
│ RP1 SDK │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Wallet │ │ Client │ │ Privacy │ │ DeFi │ │
│ │ Module │ │ Module │ │ Module │ │ Module │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Oracle │ │ Staking │ │ Gov │ │
│ │ Module │ │ Module │ │ Module │ │
│ └──────────┘ └──────────┘ └──────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Transport Layer (REST / gRPC / WS) │
├─────────────────────────────────────────────────────────────┤
│ RP1 Network │
└─────────────────────────────────────────────────────────────┘
Core Modules
Client
Base client for network connections, queries, and transactions.
const client = new RP1Client('https://rpc.rp.one');
Wallet
Key management and signing operations.
const wallet = Wallet.fromMnemonic(mnemonic);
const wallet2 = Wallet.fromPrivateKey(privateKey);
const wallet3 = Wallet.generate(); // New random wallet
Privacy
Shielded transactions and viewing keys.
const privacy = new PrivacyModule(client);
await privacy.shield(wallet, amount, denom);
await privacy.transfer(wallet, recipient, amount);
await privacy.unshield(wallet, amount, denom);
DeFi
DEX, lending, and trading operations.
const dex = new DEXModule(client);
await dex.swap(wallet, { poolId, tokenIn, minTokenOut });
const lending = new LendingModule(client);
await lending.supply(wallet, amount, denom);
await lending.borrow(wallet, amount, denom);
Oracle
Price feed queries.
const oracle = new OracleModule(client);
const price = await oracle.getPrice('BTC');
const prices = await oracle.getAllPrices();
Staking
Delegation and validator operations.
const staking = new StakingModule(client);
await staking.delegate(wallet, validatorAddress, amount);
await staking.undelegate(wallet, validatorAddress, amount);
Configuration
const client = new RP1Client('https://rpc.rp.one', {
// Gas configuration
gasPrice: '0.025urp1',
gasAdjustment: 1.3,
// Timeouts
broadcastTimeout: 60000,
pollInterval: 1000,
// Custom endpoints
apiEndpoint: 'https://api.rp.one',
grpcEndpoint: 'grpc.rp.one:9090',
});
Error Handling
import { RP1Error, InsufficientFundsError, TxFailedError } from '@rp1/sdk';
try {
await client.send({ ... });
} catch (error) {
if (error instanceof InsufficientFundsError) {
console.log('Not enough balance');
} else if (error instanceof TxFailedError) {
console.log(`Transaction failed: ${error.code} - ${error.message}`);
} else if (error instanceof RP1Error) {
console.log(`RP1 error: ${error.message}`);
}
}
TypeScript Support
Full TypeScript support with complete types:
import type {
Balance,
Transaction,
Pool,
Position,
Price,
ViewingKeyGrant,
} from '@rp1/sdk';
Browser Support
The SDK works in both Node.js and browsers:
<script type="module">
import { RP1Client } from 'https://cdn.rp.one/sdk/latest/index.mjs';
const client = new RP1Client('https://rpc.rp.one');
const balance = await client.getBalance('rp1...', 'urp1');
</script>