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

1
npm install @zetamarkets/sdk
Copied!

Getting started

Setting up a wallet

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

Basic setup boilerplate

1
// Loads the local .env file into `process.env`.
2
require("dotenv").config();
3
​
4
import { Connection, Keypair } from "@solana/web3.js";
5
import { Client, Exchange, Network, Wallet, utils, types} from "@zetamarkets/sdk";
6
import fetch from "node-fetch";
7
​
8
// Loads the private key in .env
9
const privateKey = Keypair.fromSecretKey(
10
new Uint8Array(JSON.parse(Buffer.from(process.env.private_key).toString()))
11
);
12
const wallet = new Wallet(privateKey);
13
​
14
// Starts a solana web3 connection to an RPC endpoint
15
const connection = new Connection(networkUrl, utils.defaultCommitment());
16
​
17
// Airdrop some SOL to your wallet
18
await connection.requestAirdrop(wallet.publicKey, 100000000);
19
​
20
// USDC faucet - Mint $10,000 USDC (Note USDC is fake on devnet)
21
await fetch(`${SERVER_URL}/faucet/USDC`, {
22
method: "post",
23
body: JSON.stringify({
24
key: wallet.publicKey.toString(),
25
amount: 10_000,
26
}),
27
headers: { "Content-Type": "application/json" },
28
});
29
​
30
// Loads the SDK exchange singleton. This can take up to 10 seconds...
31
await Exchange.load(
32
PROGRAM_ID,
33
Network.DEVNET,
34
connection,
35
utils.defaultCommitment(),
36
undefined, // Exchange wallet can be ignored for normal clients.
37
0 // ThrottleMs - increase if you are running into rate limit issues on startup.
38
undefined, // Callback - See below for more details.
39
);
Copied!

Displaying exchange state

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