@whalesmarket/mobile-sdk
v0.1.41
Published
Mobile-friendly Whales SDK without Anchor dependency
Readme
Whales Mobile SDK
A mobile-friendly version of the Whales SDK for React Native applications. This SDK provides the same functionality as the original Whales SDK but without the Anchor dependency, making it compatible with React Native.
Installation
# Using npm
npm install whales-mobile-sdk
# Using yarn
yarn add whales-mobile-sdk
# Using pnpm
pnpm add whales-mobile-sdkUsage
import { PreMarketSolanaMobile } from 'whales-mobile-sdk';
import { Connection } from '@solana/web3.js';
// Initialize the SDK
const connection = new Connection('https://api.mainnet-beta.solana.com');
const programId = 'your_program_id';
const apiBaseUrl = 'https://your-api-endpoint.com';
const preMarket = new PreMarketSolanaMobile(connection, programId, apiBaseUrl);
// Initialize the PreMarket
await preMarket.initialize({ configAccountPubKey: 'your_config_account' });
// Set a signer
import { Keypair } from '@solana/web3.js';
const keypair = Keypair.generate();
preMarket.setSigner(keypair);
// Create an offer
const offerTx = await preMarket.createOffer({
offerType: 0, // 0 for buy, 1 for sell
tokenId: '1',
amount: 1,
value: 1,
exToken: 'So11111111111111111111111111111111111111112', // SOL
fullMatch: false
});
// Sign and send the transaction
const result = await preMarket.signAndSendTransaction(offerTx);
console.log('Transaction hash:', result.transaction.hash);API Server Requirements
This SDK requires an API server that implements the following endpoints:
GET /offers/{offerId}: Get offer account dataGET /orders/{orderId}: Get order account dataGET /config/{configAccountPubKey}: Get config account dataGET /tokens/{tokenId}/config: Get token config account dataGET /ex-tokens/{tokenAddress}: Get ex-token account dataPOST /bootstrap: Bootstrap the PreMarketGET /offers/last-id: Get the last offer IDGET /orders/last-id: Get the last order IDPOST /offers/create: Create an offerPOST /offers/{offerId}/fill: Fill an offerPOST /offers/{offerId}/close: Close an unfilled offerPOST /orders/{orderId}/settle: Settle an orderPOST /ex-tokens/set-acceptance: Set ex-token acceptancePOST /orders/{orderId}/settle-with-discount: Settle an order with discountPOST /orders/{orderId}/cancel: Cancel an order
API Response Format
The API server should return responses in the following format:
Offer Account
{
"id": 1,
"offerType": "Buy",
"tokenConfig": "1",
"exToken": "So11111111111111111111111111111111111111112",
"totalAmount": 1000000,
"price": 1000000000,
"collateral": 0,
"filledAmount": 0,
"status": "Open",
"authority": "11111111111111111111111111111111",
"isFullMatch": false
}Order Account
{
"offer": 1,
"amount": 1000000,
"seller": "11111111111111111111111111111111",
"buyer": "11111111111111111111111111111111",
"status": "Open"
}Config Account
{
"feeRefund": 10,
"feeSettle": 10,
"feeWallet": "11111111111111111111111111111111"
}Transaction Response
{
"transaction": "base64_encoded_transaction"
}License
MIT
