Skip to content

Commit b9cb39c

Browse files
authored
fix: wait for tx confirmation on solana keypair send tx (#95)
* Wait for confirmation * Add changesets * Fix lint
1 parent 96f6860 commit b9cb39c

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"goat-examples-vercel-ai-solana": patch
3+
"@goat-sdk/wallet-solana": patch
4+
---
5+
6+
Wait for transaction confirmation

typescript/examples/vercel-ai/solana/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const keypair = Keypair.fromSecretKey(base58.decode(process.env.SOLANA_PRIVATE_K
2727
const result = await generateText({
2828
model: openai("gpt-4o-mini"),
2929
tools: tools,
30-
maxSteps: 5,
30+
maxSteps: 10,
3131
prompt: "Swap 0.05 USDC to GOAT, return the transaction hash, make sure you check i have enough USDC to cover the swap",
3232
});
3333

typescript/packages/wallets/solana/src/SolanaKeypairWalletClient.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,20 @@ export class SolanaKeypairWalletClient extends SolanaWalletClient {
4141

4242
const hash = await this.connection.sendTransaction(transaction, {
4343
maxRetries: 5,
44+
preflightCommitment: "confirmed",
4445
});
46+
47+
const newLatestBlockhash = await this.connection.getLatestBlockhash();
48+
49+
await this.connection.confirmTransaction(
50+
{
51+
blockhash: newLatestBlockhash.blockhash,
52+
lastValidBlockHeight: newLatestBlockhash.lastValidBlockHeight,
53+
signature: hash,
54+
},
55+
"confirmed",
56+
);
57+
4558
return {
4659
hash,
4760
};

0 commit comments

Comments
 (0)