File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed
packages/plugins/spl-token/src Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @goat-sdk/plugin-spl-token " : patch
3
+ ---
4
+
5
+ Improve error handling
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export class TransferTokenByMintAddressParameters extends createToolParameters(
18
18
z . object ( {
19
19
mintAddress : z . string ( ) . describe ( "The mint address of the token to transfer" ) ,
20
20
to : z . string ( ) . describe ( "The address to transfer the token to" ) ,
21
- amount : z . string ( ) . describe ( "The amount of tokens to transfer" ) ,
21
+ amount : z . string ( ) . describe ( "The amount of tokens to transfer in base unit " ) ,
22
22
} ) ,
23
23
) { }
24
24
Original file line number Diff line number Diff line change @@ -49,9 +49,24 @@ export class SplTokenService {
49
49
parameters : GetTokenBalanceByMintAddressParameters ,
50
50
) {
51
51
const { walletAddress, mintAddress } = parameters ;
52
- const tokenAccount = getAssociatedTokenAddressSync ( new PublicKey ( mintAddress ) , new PublicKey ( walletAddress ) ) ;
53
- const balance = walletClient . getConnection ( ) . getTokenAccountBalance ( tokenAccount ) ;
54
- return balance ;
52
+ try {
53
+ const tokenAccount = getAssociatedTokenAddressSync (
54
+ new PublicKey ( mintAddress ) ,
55
+ new PublicKey ( walletAddress ) ,
56
+ ) ;
57
+
58
+ const accountExists = await doesAccountExist ( walletClient . getConnection ( ) , tokenAccount ) ;
59
+
60
+ if ( ! accountExists ) {
61
+ return 0 ;
62
+ }
63
+
64
+ const balance = await walletClient . getConnection ( ) . getTokenAccountBalance ( tokenAccount ) ;
65
+
66
+ return balance ;
67
+ } catch ( error ) {
68
+ throw new Error ( `Failed to get token balance: ${ error } ` ) ;
69
+ }
55
70
}
56
71
57
72
@Tool ( {
You can’t perform that action at this time.
0 commit comments