Clockwork SDK
Clockwork Typescript SDK
Getting Started
For a quickstart guide and in depth tutorials, see the Clockwork Docs.
To jump straight to examples, go here. For the latest Rust API documentation, see Clockwork Rust SDK.
Note
- Clockwork SDK is in active development, so all APIs are subject to change.
- This code is unaudited. Use at your own risk.
Usage
First, initialize a ClockworkProvider
const wallet = new NodeWallet(new Keypair());
const connection = new Connection(clusterApiUrl("devnet"));
const provider = new ClockworkProvider(wallet, connection);
Get Thread Address
let [pubkey, bump] = provider.getThreadPDA(
wallet.publicKey,
"ThreadProgramTest"
);
Initialize a Thread
let tx = await provider.threadCreate(
wallet.publicKey,
"ThreadProgramTest",
[],
{ now: {} },
0.1 * LAMPORTS_PER_SOL
);
Get Thread Data Deserialized
let threadAccount = await provider.getThreadAccount(threadPubkey);
Pause/Resume/Reset/Delete/ Thread
let tx = await provider.threadPause(wallet.publicKey, threadPubkey);
let tx = await provider.threadResume(wallet.publicKey, threadPubkey);
let tx = await provider.threadReset(wallet.publicKey, threadPubkey);
let tx = await provider.threadDelete(wallet.publicKey, threadPubkey);
Update a Thread
let tx = await provider.threadUpdate(wallet.publicKey, threadPubkey, {
name: "TestUpdateThread",
rateLimit: new BN(32),
trigger: { now: {} },
});
Withdraw from Thread
let tx = await provider.threadWithdraw(
wallet.publicKey,
threadPubkey,
0.01 * LAMPORTS_PER_SOL
);
Get Crate Info
let tx = await provider.getCrateInfo();
Get Worker Address
let [pubkey, bump] = provider.getWorkerPDA("8");
Get Worker Account
let workerAccount = await provider.getWorkerAccount(workerPubkey);