Private Key Wallet SDK

How to Install the sdk in your project

npm i @openocean.finance/limitorder-sdk

How to use the sdk in your project

import { openoceanLimitOrderSdk } from '@openocean.finance/limitorder-sdk';

You can then use all the functions explored by the SDK (API and swapSdk).

Setup with Private Key Wallet

1. Configuration

const privateKey = 'YOUR_PRIVATE_KEY';
const chainId = '8453';
const providerUrl = 'https://base.llamarpc.com';
const baseUrl = 'https://open-api.openocean.finance';

const inToken = {
  address: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC
  decimals: 6
};

const outToken = {
  address: '0xfde4c96c8593536e31f229ea8f37b2ada2699bb2', // USDT
  decimals: 6
};

2. Web3.js Setup

3. Ethers.js Setup

Ethers v5

Ethers v6 Warning

If using Ethers v6, make sure to import correctly:

Creating a Limit Order

Canceling a Limit Order

Querying Orders

Notes

  • Ethers v5 vs v6:

    • v5 uses new ethers.providers.JsonRpcProvider() and Wallet()

    • v6 uses JsonRpcProvider and Wallet from ethers6, and BigInt types

    • SDK supports both, but ensure correct version imports

  • Gas Price:

    • For Web3.js: await web3.eth.getGasPrice()

    • For Ethers: await provider.getFeeData().gasPrice

  • Order Expiration Options:

    • '1H', '6H', '12H', '1D', '3D', '1W', '6Month'

Demo

Last updated