Rain SDK
npm install @rainprotocolsdk/sdkRain SDK is designed as a clean, modular, and extensible TypeScript SDK for interacting with Rain markets and preparing on-chain transactions.
The SDK is intentionally split into two layers:
* Rain → Stateless, public-facing utilities (data fetching, raw transaction builders)
* RainAA → Stateful Account Abstraction layer (smart accounts)
---
``bash`
npm install @rainprotocolsdk/sdk
or
`bash`
yarn add @rainprotocolsdk/sdk
---
`ts
import { Rain } from "@rainprotocolsdk/sdk";
const rain = new Rain();
`
> The constructor is intentionally empty to allow future configuration without breaking changes.
---
Fetches public market data from the Rain backend.
`ts`
getPublicMarkets(params: GetMarketsParams): Promise
`ts`
interface GetMarketsParams {
limit: number;
offset: number;
sortBy?: "Liquidity" | "Volumn" | "latest";
status?: 'Live' | 'New' | 'WaitingForResult' | 'UnderDispute' | 'UnderAppeal' | 'ClosingSoon' | 'InReview' | 'InEvaluation' | 'Closed' | 'Trading';
}
`ts`
const markets = await rain.getPublicMarkets({
limit?: 12,
offset?: 1,
sortBy?: "Liquidity",
status?: "Live",
});
---
`
Builds a raw ERC20 approval transaction if needed.
This function prepares an unsigned approve(spender, amount) transaction and does not execute it.
If amount is not provided, a default large allowance is approved.
`
`ts0x${string}
interface RawTransaction {
to: ;0x${string}
data: ;`
}
`ts0x${string}
const approvalTx = rain.buildApprovalTx({
tokenAddress: , // Approval token address 0x${string}
spender: , // Market contract address`
amount?: 1000000000000000000n // optional parameter
});
---
Builds a raw EVM transaction for entering a market option.
This function does not send the transaction — it only prepares calldata.
`ts`
buildBuyOptionRawTx(params: EnterOptionTxParams): RawTransaction;
`ts0x${string}
interface EnterOptionTxParams {
address: ; // Trademarket contract address`
selectedOption: number; // Option index
buyInWei: bigint; // Amount in wei
}
`ts0x${string}
interface RawTransaction {
to: ;0x${string}
data: ;`
}
`ts0x${string}
const rawTx = rain.buildBuyOptionRawTx({
address: ,`
selectedOption: 1,
buyInWei: 1000000000000000000n,
});
---
Builds a raw EVM transaction for placing a limit buy order on a Rain market.
This function does not send the transaction — it only prepares calldata.
`ts`
buildLimitBuyOptionTx(params: EnterLimitOptionTxParams): RawTransaction
`ts0x${string}
interface EnterLimitOptionTxParams {
marketContractAddress: ; // market contract address6
selectedOption: number; // Option index
pricePerShare: bigint; // price per share
buyAmountInWei: bigint; // total buy amount (already converted to token wei)
tokenDecimals?: number; // token decimals optional (default: )`
}$3
| Field | Type | Required | Description |
| ----------------------- | ------------- | -------- | ------------------------------------------------------ |
| marketContractAddress | 0x${string} | ✅ | Address of the market contract |selectedOption
| | number | ✅ | Option index to place the buy order for |pricePerShare
| | number | ✅ | Limit price per share (between 0 and 1) |buyAmountInWei
| | bigint | ✅ | Total amount to spend (already converted to token wei) |tokenDecimals
| | number | ❌ | Token decimals optional (default: 6) |
`ts0x${string}
interface RawTransaction {
to: ;0x${string}
data: ;`
}
`ts0x${string}
rain.buildLimitBuyOptionTx({
marketContractAddress: ,`
buyAmountInWei: 1000000,
pricePerShare: 0.1,
selectedOption: 1,
})
---
RainAA is responsible for:
* Smart account creation
* Session management (coming soon)
* Gas-sponsored execution (coming soon)
* Transaction submission (coming soon)
> RainAA consumes raw transactions generated by Rain.
`ts`
Rain (WHAT to do)
↓
Raw Transaction
↓
RainAA (HOW to execute)
Rain SDK follows Semantic Versioning:
* Patch (1.0.x) → Bug fixes1.x.0
* Minor () → New features, backward compatiblex.0.0
* Major () → Breaking API changes
---
`ts
// 1. Read data / build tx
const rain = new Rain();
const rawTx = rain.buildBuyOptionRawTx(...);
// 2. Execute via your provider
await yourprovider.sendTransaction(rawTx);
``
---
Rain SDK is built to scale with both products and protocols.