MCPcopy Create free account
hub / github.com/clockwork-xyz/examples / initializeThread

Function initializeThread

event_stream/tests/event_stream.ts:64–104  ·  view source on GitHub ↗
(event: PublicKey)

Source from the content-addressed store, hash-verified

62
63
64const initializeThread = async (event: PublicKey) => {
65
66 // 1️⃣ Ask your Program to do a CPI to create a Thread
67 try {
68 const tx = await program.methods.initialize(Buffer.from(threadId))
69 .accounts({
70 systemProgram: SystemProgram.programId,
71 clockwork: clockworkProvider.threadProgram.programId,
72 signer: provider.publicKey,
73 authority: threadAuthority,
74 eventThread: threadAddress,
75 event: event,
76 })
77 .rpc();
78 print_address("🤖 Program", program.programId.toString());
79 print_thread_address("🧵 Thread", threadAddress);
80 print_tx("✍️ Tx", tx);
81 } catch (e) {
82 // ❌
83 // 'Program log: Instruction: ThreadCreate',
84 // 'Program 11111111111111111111111111111111 invoke [2]',
85 // 'Allocate: account Address { address: ..., base: None } already in use'
86 //
87 // -> If you encounter this error, the thread address you are trying to assign is already in use,
88 // you can just change the threadLabel, to generate a new address.
89 // -> OR update the thread with a ThreadUpdate instruction (more on this in another guide)
90
91
92 // ❌
93 // 'Program log: AnchorError caused by account: thread. Error Code: AccountNotSystemOwned.
94 // Error Number: 3011. Error Message: The given account is not owned by the system program.',
95 //
96 // -> Same as the above, actually
97 // What's happening is that, the account is now owned by the ThreadProgram,
98 // and thus the Account has been successfully created.
99 // The account owner is now the ThreadProgram, but in your program you are expecting a SystemAccount
100 // -> What to do? -> (Same as the first error) for your tests it's fine to just use a new address.
101 console.error(e);
102 expect.fail(e);
103 }
104}
105
106const ping = async (event: PublicKey) => {
107 try {

Callers 1

event_stream.tsFile · 0.85

Calls 3

print_thread_addressFunction · 0.85
print_addressFunction · 0.70
print_txFunction · 0.70

Tested by

no test coverage detected