Created
March 20, 2024 06:52
-
-
Save wphan/61b261cb6ca15be4d317048136d9759b to your computer and use it in GitHub Desktop.
Minimal AuctionSubscriber Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
DriftClient, | |
AuctionSubscriber, | |
Wallet, | |
DRIFT_PROGRAM_ID, | |
} from '@drift-labs/sdk' | |
import { Connection, Keypair, PublicKey } from '@solana/web3.js'; | |
const main = async () => { | |
const connection = new Connection("ur own working rpc"); | |
const driftClient = new DriftClient({ | |
connection, | |
wallet: new Wallet(new Keypair()), | |
programID: new PublicKey(DRIFT_PROGRAM_ID), | |
accountSubscription: { | |
type: 'websocket' | |
}, | |
env: 'mainnet-beta', | |
}); | |
await driftClient.subscribe(); | |
const auctionSubscriber = new AuctionSubscriber({driftClient}); | |
await auctionSubscriber.subscribe(); | |
auctionSubscriber.eventEmitter.on('onAccountUpdate', (auction) => { | |
console.log(auction); | |
}); | |
while (true) { | |
await new Promise(resolve => setTimeout(resolve, 1000)); | |
} | |
} | |
main().then(() => { | |
process.exit(0) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment