0.3.4 • Published 12 months ago

@clockwork-xyz/sdk v0.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

License

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 clockworkProvider = new ClockworkProvider(wallet, connection);

#or
const anchorProvider = new anchor.AnchorProvider(
        connection,
        wallet,
        anchor.AnchorProvider.defaultOptions()
);
const provider = new ClockworkProvider.fromAnchorProvider(provider);

Get Thread Address

const [pubkey, bump] = provider.getThreadPDA(
      wallet.publicKey,
      "ThreadProgramTest"
);

Initialize a Thread

const ix = await provider.threadCreate(
      wallet.publicKey,         // authority
      "ThreadProgramTest",      // id
      [],                       // instructions to execute
      { now: {} },              // thread trigger
      0.1 * LAMPORTS_PER_SOL    // amount to send to the thread
);
const tx = new Transaction().add(ix);
const signature = await provider.anchorProvider.sendAndConfirm(tx);

Get Thread Data Deserialized

const threadAccount = await provider.getThreadAccount(threadPubkey);

Pause/Resume/Reset/Delete/ Thread

const ix = await provider.threadPause(wallet.publicKey, threadPubkey);
const ix = await provider.threadResume(wallet.publicKey, threadPubkey);
const ix = await provider.threadReset(wallet.publicKey, threadPubkey);
const ix = await provider.threadDelete(wallet.publicKey, threadPubkey);

Update a Thread

const ix = await provider.threadUpdate(wallet.publicKey, threadPubkey, {
      name: "TestUpdateThread",
      rateLimit: new BN(32),
      trigger: { now: {} },
});
const tx = new Transaction().add(ix);
const signature = await provider.anchorProvider.sendAndConfirm(tx);

Withdraw from Thread

const ix = await provider.threadWithdraw(
      wallet.publicKey,
      threadPubkey,
      0.01 * LAMPORTS_PER_SOL
);
const tx = new Transaction().add(ix);
const signature = await provider.anchorProvider.sendAndConfirm(tx);
0.3.2

1 year ago

0.3.1

1 year ago

0.3.4

12 months ago

0.3.3

12 months ago

0.3.0

1 year ago

0.2.4

1 year ago

0.2.1

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.1.0

1 year ago

0.2.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.2

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.6

1 year ago

0.0.1

1 year ago