pyth-crosschain/express_relay/sdk/js
Amin Moghaddam f22c0c8ae6
feat(express-relay): Support websocket in the js sdk (#1301)
2024-02-22 09:55:02 +01:00
..
src feat(express-relay): Support websocket in the js sdk (#1301) 2024-02-22 09:55:02 +01:00
.eslintrc.js Initial version of js sdk for express relay (#1281) 2024-02-08 10:56:17 +01:00
.gitignore Initial version of js sdk for express relay (#1281) 2024-02-08 10:56:17 +01:00
README.md feat(express-relay): Support websocket in the js sdk (#1301) 2024-02-22 09:55:02 +01:00
package.json feat(express-relay): Support websocket in the js sdk (#1301) 2024-02-22 09:55:02 +01:00
tsconfig.json Initial version of js sdk for express relay (#1281) 2024-02-08 10:56:17 +01:00

README.md

Pyth Express Relay JS SDK

Utility library for interacting with the Pyth Express Relay API.

Installation

npm

$ npm install --save @pythnetwork/express-relay-evm-js

Yarn

$ yarn add @pythnetwork/express-relay-evm-js

Development

To generate the latest type declarations from the server openapi schema, run:

npm run generate-api-types

Quickstart

import {
  Client,
  OpportunityParams,
  BidInfo,
} from "@pythnetwork/express-relay-evm-js";

const client = new Client({ baseUrl: "https://per-staging.dourolabs.app/" });

function calculateOpportunityBid(opportunity: Opportunity): BidInfo | null {
  // searcher implementation here
  // if the opportunity is not suitable for the searcher, return null
}

client.setOpportunityHandler(async (opportunity: Opportunity) => {
  const bidInfo = calculateOpportunityBid(opportunity);
  if (bidInfo === null) return;
  const opportunityBid = await client.signOpportunityBid(
    opportunity,
    bidInfo,
    privateKey // searcher private key with appropriate permissions and assets
  );
  await client.submitOpportunityBid(opportunityBid);
});
await client.subscribeChains([chain_id]); // chain id you want to subscribe to

Example

There is an example searcher in examples directory.

SimpleSearcher

This example fetches OpportunityParams from the specified endpoint, creates a fixed bid on each opportunity and signs them with the provided private key, and finally submits them back to the server. You can run it with npm run simple-searcher. A full command looks like this:

npm run simple-searcher -- \
  --endpoint https://per-staging.dourolabs.app/ \
  --bid 100000 \
  --chain-id op_sepolia \
  --private-key <YOUR-PRIVATE-KEY>