Zeta
Search…
🧱
Zeta SDK
We've open sourced our SDK for Mainnet. Our SDK is a typescript library that can be used to interact with our Zeta program smart contract.
For more details on how the SDK can be used, please take a look at the SDK documentation which can be found at the following urls:

Install

npm install @zetamarkets/sdk

Getting started

Setting up a wallet

# Generate new keypair at ./bot-key.json
solana-keygen new -o bot-key.json
​
# View new pubkey address
solana-keygen pubkey bot-key.json
​
# Put private key into .env file used by script
# (Make sure you are in the same directory as where you are running the script.)
echo private_key=`cat bot-key.json` >> .env

Basic setup boilerplate

// Loads the local .env file into `process.env`.
require("dotenv").config();
​
import { Connection, Keypair } from "@solana/web3.js";
import { Client, Exchange, Network, Wallet, utils, types} from "@zetamarkets/sdk";
import fetch from "node-fetch";
​
// Loads the private key in .env
const privateKey = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(Buffer.from(process.env.private_key).toString()))
);
const wallet = new Wallet(privateKey);
​
// Starts a solana web3 connection to an RPC endpoint
const connection = new Connection(networkUrl, utils.defaultCommitment());
​
// Airdrop some SOL to your wallet
await connection.requestAirdrop(wallet.publicKey, 100000000);
​
// USDC faucet - Mint $10,000 USDC (Note USDC is fake on devnet)
await fetch(`${SERVER_URL}/faucet/USDC`, {
method: "post",
body: JSON.stringify({
key: wallet.publicKey.toString(),
amount: 10_000,
}),
headers: { "Content-Type": "application/json" },
});
​
// Loads the SDK exchange singleton. This can take up to 10 seconds...
await Exchange.load(
PROGRAM_ID,
Network.DEVNET,
connection,
utils.defaultCommitment(),
undefined, // Exchange wallet can be ignored for normal clients.
0 // ThrottleMs - increase if you are running into rate limit issues on startup.
undefined, // Callback - See below for more details.
);

Displaying exchange state

// Display existing exchange state i.e. markets available and their indices.
// Can only be run after `Exchange` is loaded.
utils.displayState();
​
`
[EXCHANGE] Display market state...
Expiration @ Thu Nov 18 2021 08:00:00 GMT+0800
[MARKET] INDEX: 23 KIND: call STRIKE: 220
[MARKET] INDEX: 24 KIND: call STRIKE: 223
[MARKET] INDEX: 25 KIND: call STRIKE: 226
// ... Deleted for space ...
[MARKET] INDEX: 44 KIND: put STRIKE: 260
[MARKET] INDEX: 45 KIND: future STRIKE: 0
Expiration @ Fri Nov 19 2021 08:00:00 GMT+0800
[MARKET] INDEX: 0 KIND: call STRIKE: 205
[MARKET] INDEX: 1 KIND: call STRIKE: 208
[MARKET] INDEX: 2 KIND: call STRIKE: 211
// ... Deleted for space ...
[MARKET] INDEX: 20 KIND: put STRIKE: 240
[MARKET] INDEX: 21 KIND: put STRIKE: 245
[MARKET] INDEX: 22 KIND: future STRIKE: 0
`
For more, be sure to check out our documentation at either of the following urls:
​
​
​
Copy link
On this page
Install
Getting started