Getting Started

Install

Using npm:

npm install @pheasant-network/pheasant-sdk

Using yarn:

yarn install @pheasant-network/pheasant-sdk

Import Module

Import as ES6 module:

This package is currently ES Module only.

import { PheasantSDK } from "@pheasant-network/pheasant-sdk"

Instantiate SDK

Instansiate using ethers signer:

import { ethers } from "ethers"
import { PheasantSDK } from "@pheasant-network/pheasant-sdk"

const provider = new ethers.providers.JsonRpcProvider(“RPC_PROVIDER_URL”);
const wallet = ethers.Wallet.fromMnemonic(“YOUR_MNEMONIC”);
const signer = wallet.connect(provider);
 
const pheasantSDK = PheasantSDK.Init(signer)

Instansiate using web3 provider as signer:

import { ethers } from "ethers"
import { PheasantSDK } from "@pheasant-network/pheasant-sdk"

const provider = new ethers.providers.Web3Provider(window.ethereum, 'any')
const signer = provider.getSigner()
 
const pheasantSDK = PheasantSDK.Init(signer)

Instansiate using hdwallet-provider signer (only Node.js):

import HDWalletProvider from "@truffle/hdwallet-provider";
import { PheasantSDK } from "@pheasant-network/pheasant-sdk"

const signer = new HDWalletProvider({
  mnemonic:YOUR_MNEMONIC,
  providerOrUrl:RPC_PROVIDER_URL, 
  chainId:CHAIN_ID
});

const pheasantSDK = PheasantSDK.Init(signer)

Demo

A simple Pheasant SDK Demo:

https://pheasant-sdk-demo.web.app/

Example

Bridge (L1 -> L2)

Please check the SDK Supported Network for keywords specifying the chain.

import HDWalletProvider from "@truffle/hdwallet-provider";
import { PheasantSDK, Token } from "@pheasant-network/pheasant-sdk"

const signer = new HDWalletProvider({
  mnemonic:YOUR_MNEMONIC,
  providerOrUrl:RPC_PROVIDER_URL, 
  chainId: 1 // ethereum chain id
});

const pheasantSDK = PheasantSDK.Init(signer)
const tx = await pheasantSDK.send("100000000", "Ethereum", "Base", Token.ETH)

Bridge (L2 -> L1) (WETH)

import HDWalletProvider from "@truffle/hdwallet-provider";
import { PheasantSDK, Token } from "@pheasant-network/pheasant-sdk"

const signer = new HDWalletProvider({
  mnemonic:YOUR_MNEMONIC,
  providerOrUrl:RPC_PROVIDER_URL, 
  chainId: 137 // polygon chain id
});

const pheasantSDK = PheasantSDK.Init(signer)

//Checking whether it has been approved.
const needsApproval = await pheasantSDK.needsApproval("100000000", Token.WETH)
await pheasantSDK.sendApproval("100000000", Token.WETH)

const tx = await pheasantSDK.send("100000000", "Polygon", "Ethereum", Token.WETH)

Bridge (L2 -> L2)

import HDWalletProvider from "@truffle/hdwallet-provider";
import { PheasantSDK, Token } from "@pheasant-network/pheasant-sdk"

const signer = new HDWalletProvider({
  mnemonic:YOUR_MNEMONIC,
  providerOrUrl:RPC_PROVIDER_URL, 
  chainId: 10 // optimism chain id
});

const pheasantSDK = PheasantSDK.Init(signer)
const tx = await pheasantSDK.send("100000000", "Optimism", "Base", Token.ETH)

Custom Recipient (L2 → L1, L2 → L2 only)

const tx = await pheasantSDK.send("100000000", "Optimism", "Base", Token.ETH, {
  recipient: "0x123..."
})

Custom Fee (L2 → L1, L2 → L2 only)

If the fee is below the threshold*, Relayer may not respond. The fee is automatically calculated without specification, but may be lower than the threshold due to fluctuations in gas prices. Therefore, you may optionally specify the fee.

*Thresholds are different for each Relayer and are managed off-chain, so they are basically private.

const tx = await pheasantSDK.send("100000000", "Optimism", "Base", Token.ETH, {
  customFee: "100000"
})

Cancel (L2 → L1, L2 → L2 only)

Users can cancel the transaction before the Relayer responds by specifying their address and the index of the transaction. The index can be obtained by getTradeList, etc., described below.

const tx = await pheasantSDK.cancel(0);

Burn (CCTP)

After a certain time after burn, CCTP will transfer USDC on the destination chain. Please check the SDK Supported Network for keywords specifying the chain.

import HDWalletProvider from "@truffle/hdwallet-provider";
import { PheasantSDK, Token } from "@pheasant-network/pheasant-sdk"

const signer = new HDWalletProvider({
  mnemonic:YOUR_MNEMONIC,
  providerOrUrl:RPC_PROVIDER_URL, 
  chainId: 10 // optimism chain id
});

const pheasantSDK = PheasantSDK.Init(signer)
const tx = await pheasantSDK.burn("100000000", "Optimism", "Base", Token.USDC)

getRelayerList

Return all Relayer per network.

const relayerList = await PheasantSDK.getRelayerList("Optimism")

getTradeList

Get trade at the specified address. The start and end indexes can be specified optionally. If not specified, all trades are retrieved.

const tradeList = await PheasantSDK.getTradeList("YOUR_ADDRESS", "Optimism")
const tradeList = await PheasantSDK.getTradeList("YOUR_ADDRESS", "Optimism", 0, 2)

getTradeThreshold

const threshold = await PheasantSDK.getThreshold("Optimism")

getTradeMinimum

const minimum = await PheasantSDK.getTradeMinimum("Optimism")

getApprovalTargetAddress

const address = await PheasantSDK.getApprovalTargetAddress("Optimism")

getApprovalTokenAddress

const address = await PheasantSDK.getApprovalTokenAddress("Polygon", Token.WETH)

Last updated