@stakefish/sdk-sui
v0.0.1-rc.3
Published
stake.fish SUI staking SDK
Readme
@stakefish/sdk-sui
The @stakefish/sdk-sui is a JavaScript/TypeScript library that provides a unified interface for staking operations on the Sui blockchain with stake.fish validators. It allows developers to easily delegate stakes, undelegate, sign transactions, and broadcast them to the network.
Table of Contents
Installation
To use this SDK in your project, install it via npm or yarn:
npm install @stakefish/sdk-suiyarn add @stakefish/sdk-suiAPI Reference
Constructor
interface SuiConfig {
rpcUrl?: string;
}
export class Sui {
constructor(config?: SuiConfig)
...rpcUrl(optional): Custom Sui RPC endpoint URL (default: 'https://fullnode.mainnet.sui.io')
Delegation
delegate(delegatorAddress: string, amount: string): Promise<SuiUnsignedTransaction>Creates an unsigned transaction for delegating a specified amount of SUI tokens (in MIST, the smallest unit) from the delegator's address to the stake.fish validator.
Parameters:
delegatorAddress: The Sui address of the delegator (e.g., '0x123...')amount: The amount to delegate in MIST (1 SUI = 1,000,000,000 MIST)
Undelegation
undelegate(delegatorAddress: string, stakeId: string): Promise<SuiUnsignedTransaction>Creates an unsigned transaction for undelegating from a specific stake position identified by stakeId. The entire stake is withdrawn.
Parameters:
delegatorAddress: The Sui address of the delegatorstakeId: The unique identifier (object ID) of the stake position to undelegate. You can find this on Suiscan or by querying your stake positions.
Signing
sign(privateKey: string, unsignedTx: SuiUnsignedTransaction): Promise<SuiSignedTransaction>Signs the unsigned transaction using the provided private key. This operation works completely offline and does not require network connectivity.
Parameters:
privateKey: The private key in one of the following formats:- Bech32 encoded (e.g.,
suiprivkey1...) - Standard Sui wallet export format - Hex with
0xprefix (e.g.,0x1234...) - Raw hex without prefix (e.g.,
1234...)
- Bech32 encoded (e.g.,
unsignedTx: The unsigned transaction object fromdelegate()orundelegate()
Broadcasting
broadcast(signedTransaction: SuiSignedTransaction, checkInclusion?: boolean, timeoutMs?: number, pollIntervalMs?: number): Promise<SuiTransactionBroadcastResult>Broadcasts the signed transaction to the Sui network and optionally waits for inclusion confirmation.
Parameters:
signedTransaction: The signed transaction object fromsign()checkInclusion(optional): Whether to wait for transaction inclusion (default:true)timeoutMs(optional): Maximum time to wait for inclusion in milliseconds (default:60000)pollIntervalMs(optional): Interval between inclusion checks in milliseconds (default:2000)
Returns: SuiTransactionBroadcastResult object containing:
txId: The transaction digest/hashsuccess: Boolean indicating if the transaction was successfulerror: Error message if the transaction failed (optional)
Examples
Full delegation example
import { Sui } from '@stakefish/sdk-sui';
// or: const { Sui } = require('@stakefish/sdk-sui');
const delegator = process.env.SUI_ADDRESS;
const privateKey = process.env.SUI_PRIVATE_KEY;
async function main() {
const sui = new Sui();
// Delegation (1 SUI = 1,000,000,000 MIST)
const tx = await sui.delegate(delegatorAddress, '1000000000');
// Sign
const signedTx = await sui.sign(privateKey, tx);
// Broadcast
const result = await sui.broadcast(signedTx);
console.log('Broadcast result:', JSON.stringify(result));
}
void main().catch(console.error);Undelegation
const tx = await sui.undelegate(delegatorAddress, stakeId);Configuration
The SDK uses default RPC endpoints for Sui mainnet. You can configure custom endpoints and options during instantiation:
const sui = new Sui({
rpcUrl: 'https://custom-rpc.sui.io',
});Notes
- All amounts in the SDK are specified in MIST, the smallest unit of SUI (1 SUI = 1,000,000,000 MIST)
- The SDK automatically handles gas estimation and payment for transactions
- Private keys should be kept secure and never committed to version control
