Skip to content

Getting Started using the core package

Overview

The Omni SDK contains APIs for interfacing with Omni SolverNet, your gateway to enabling any transaction, on any chain, from any supported JavaScript runtime.

Prerequisites

You'll need to have viem setup in your project already. If you don't, you can follow the instructions here: Viem Getting Started Guide.

Installation

Once your project meets the prerequisites, install the SDK package:

pnpm
pnpm i @omni-network/core

Setup

Environment

The SDK supports the following environments for interacting with the SolverNet APIs:

  • mainnet for production (default when not specified)
  • testnet for development and testing

Some of the SDK functions support providing the environment as a parameter. If not provided, the SDK will use mainnet.

Contracts

Functions interacting with blockchains need to be provided the contract addresses, which can be loaded using the getContracts() function:

import { getContracts, getOrder } from '@omni-network/core'
 
const mainnetAddresses = getContracts() // mainnet environment by default
const testnetAddresses = getContracts('testnet')
 
const order = await getOrder({
  client: publicClient,
  inboxAddress: mainnetAddresses.inbox,
  orderId: '0x123...',
})

Viem clients

The SDK uses viem clients for blockchain interactions.

Most functions only perform read operations using a Public Client, however the order creation functions (sendOrder, openOrder and generateOrder) need to be provided a Wallet Client able to sign transactions.

import { getOrder, openOrder } from '@omni-network/core'
import { createPublicClient, createWalletClient, custom, http } from 'viem'
import { mainnet } from 'viem/chains'
 
// Example Public Client from viem's documentation
const publicClient = createPublicClient({
  chain: mainnet,
  transport: http()
})
// Retrieving a known order only needs a Public Client
const order = await getOrder({
  client: publicClient,
  inboxAddress: mainnetAddresses.inbox,
  orderId: '0x123...',
})
 
// Example Wallet Client from viem's documentation
const walletClient = createWalletClient({
  chain: mainnet,
  transport: custom(window.ethereum!)
})
// Opening an order requires a Wallet Client
const order = await openOrder({
  client: walletClient,
  inboxAddress: mainnetAddresses.inbox,
  order: orderParameters,
})