Skip to content

Commit

Permalink
fix: wait for tx confirmation on solana keypair send tx (#95)
Browse files Browse the repository at this point in the history
* Wait for confirmation

* Add changesets

* Fix lint
  • Loading branch information
0xaguspunk authored Dec 18, 2024
1 parent 96f6860 commit b9cb39c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions typescript/.changeset/grumpy-donkeys-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"goat-examples-vercel-ai-solana": patch
"@goat-sdk/wallet-solana": patch
---

Wait for transaction confirmation
2 changes: 1 addition & 1 deletion typescript/examples/vercel-ai/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const keypair = Keypair.fromSecretKey(base58.decode(process.env.SOLANA_PRIVATE_K
const result = await generateText({
model: openai("gpt-4o-mini"),
tools: tools,
maxSteps: 5,
maxSteps: 10,
prompt: "Swap 0.05 USDC to GOAT, return the transaction hash, make sure you check i have enough USDC to cover the swap",
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ export class SolanaKeypairWalletClient extends SolanaWalletClient {

const hash = await this.connection.sendTransaction(transaction, {
maxRetries: 5,
preflightCommitment: "confirmed",
});

const newLatestBlockhash = await this.connection.getLatestBlockhash();

await this.connection.confirmTransaction(
{
blockhash: newLatestBlockhash.blockhash,
lastValidBlockHeight: newLatestBlockhash.lastValidBlockHeight,
signature: hash,
},
"confirmed",
);

return {
hash,
};
Expand Down

0 comments on commit b9cb39c

Please sign in to comment.