时钟 SDK
时钟打字机 SDK
开始
关于快速启动的指南和深入的教程,见 时钟文件。 。 。 . 直跳到例子,走 这里。关于最新的 Rust API 文件,请参见 时钟 Rust SDK。 。 。 .
说明
- Clockwork SDK正在积极开发,因此所有API都会被改变.
- 此代码未经审计. 自己冒险使用.
使用量
首先,初始化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);
获取线索地址
const [pubkey, bump] = provider.getThreadPDA(
wallet.publicKey,
"ThreadProgramTest"
);
初始化线索
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);
获取串行数据去序列化
const threadAccount = await provider.getThreadAccount(threadPubkey);
暂停/恢复/重置/删除/线索
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);
更新线索
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);
退出线索
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);