@abstraxn/solana-relayer
v1.0.0
Published
Abstraxn Solana Relayer SDK for building, signing, and relaying Solana transactions.
Downloads
641
Readme
Abstraxn Solana Relayer SDK
Overview
The Abstraxn Solana Relayer SDK provides a class-based client to:
- build native or SPL-token transfer transactions with one API
- sign transactions with wallet adapters
- submit signed transactions to sol-relayer-hub
- fetch transaction status
This package targets the current Sol relayer API flow.
Installation
Using npm:
npm install @abstraxn/solana-relayerUsing yarn:
yarn add @abstraxn/solana-relayerUsage
import { Connection, PublicKey } from "@solana/web3.js";
import { SolanaRelayer } from "@abstraxn/solana-relayer";
const client = new SolanaRelayer({
relayerUrl: "https://solana.abstraxn.com/api/v1/103?apikey=your_api_key",
});
const connection = new Connection("https://api.devnet.solana.com", "confirmed");
const { tx, lastValidBlockHeight } = await client.buildTx({
connection,
sender: new PublicKey("<user-wallet-pubkey>"),
to: new PublicKey("<recipient-pubkey>"),
lamports: 1000000,
});
const serializedUserSignedTx = await client.signTx({
wallet: walletAdapter,
transaction: tx,
});
const submit = await client.sendTx({
signedTransaction: serializedUserSignedTx,
lastValidBlockHeight,
});
const finalStatus = await client.getTxStatus({
txnId: submit.txnId,
});
console.log(finalStatus.status, finalStatus.signature);Token transfer with program overrides
const { tx, lastValidBlockHeight } = await client.buildTx({
connection,
sender: new PublicKey("<owner-pubkey>"),
mint: new PublicKey("<mint-address>"),
recipientOwner: new PublicKey("<recipient-owner-pubkey>"),
amountUi: "1.25",
decimals: 6,
splTokenProgramId: new PublicKey("<token-program-id>"), // required
splAssociatedTokenProgramId: new PublicKey("<ata-program-id>"), // required
});Custom program transaction (no static SDK program dependency)
import { TransactionInstruction } from "@solana/web3.js";
const instructions: TransactionInstruction[] = [
// Build any instructions with your own programId/accounts/data
];
const { tx, lastValidBlockHeight } = await client.buildTx({
connection,
sender: new PublicKey("<signer-pubkey>"),
instructions,
});API
buildTx(params)signTx(params)sendTx(params)getTxStatus(params)
Runtime flow
buildTx()fetches an available relayer and reserves it.- SDK stores
reservationTokeninternally from that reservation. signTx()signs the built transaction with user wallet.sendTx()submits signed tx with stored reservation token.getTxStatus()fetches relay status bytxnId.
sendTx() must be called after a successful buildTx() call.
lastValidBlockHeight should be the value returned by buildTx().
relayerUrl is configured once in SolanaRelayerConfig.
SDK uses a single EVM-style method endpoint contract:
- all operations are
POST <relayerUrl> - request body carries
{ method, params, id, jsonrpc } - methods used by SDK:
sol_getAvailableRelayersol_sendTx/sol_sendProgrammeTxsol_getTxStatus
buildTx(params) accepts exactly one mutually exclusive branch:
- native:
to + lamports - token:
mint + recipientOwner + amountUi + decimals + splTokenProgramId + splAssociatedTokenProgramId - custom:
instructionsortransaction
Local Backend Test Flow
Use this sequence to validate SDK integration against local sol-relayer-hub.
1) Start backend services
From solana-relayer/sol-relayer-hub:
npm install
npm run start:devEnsure health is reachable:
curl -sS http://localhost:3010/health2) Build SDK
From abstraxn-sdks/solana-relayer:
npm install
npm run build3) Wire FE to local SDK source (recommended for local development)
In sol-relayer-test-fe/src/solana.ts, import from:
../../../abstraxn-sdks/solana-relayer/srcThis avoids global npm link issues and always uses your latest local SDK code.
4) Build FE
From solana-relayer/sol-relayer-test-fe:
npm install
npm run build5) Runtime checks
GET /relayer/availableshould return one relayer or 404.POST <relayerUrl>with invalid payload should return validation error.- FE happy path should produce:
- relay submit response with
txnId - terminal status (
confirmedorfailed) from status API.
- relay submit response with
Example negative check:
curl -sS -X POST "http://localhost:3010/api/v1/103?apikey=dev_local_api_key" \
-H "Content-Type: application/json" \
-d '{"method":"sol_sendTx","params":[{"serializedUserSignedTx":"abcd","reservationToken":"token","lastValidBlockHeight":1}],"id":1,"jsonrpc":"2.0"}'Acceptance Criteria
- SDK builds cleanly.
- FE builds while importing SDK client methods.
- Local hub endpoints are reachable.
- Submit/status flow works via SDK methods in FE for at least one runtime scenario.
