espresso-cash-public
espresso-cash-public copied to clipboard
[issue] Can't subscribe to a token account
Hey 🖖🏻
I am trying to subscribe to a token account but it always throws me an error.
Code example:
import 'package:solana/dto.dart';
import 'package:solana/solana.dart';
void main(List<String> arguments) async {
final subClient = SubscriptionClient(
Uri.parse("wss://api.devnet.solana.com"),
);
final client = SolanaClient(
rpcUrl: Uri.parse("https://api.devnet.solana.com"),
websocketUrl: Uri.parse("wss://api.devnet.solana.com"),
);
final tokenAccount = await client.getAssociatedTokenAccount(
owner: "6moute4cAhkmhA5VGrmhFB3cbZJRCwSoxHe8ZEiPAQRi",
mint: "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr",
);
print("token account -> ${tokenAccount!.pubkey}");
final stream = subClient.accountSubscribe(
tokenAccount.pubkey,
commitment: Commitment.confirmed,
);
stream.forEach((element) {
print(element);
});
print("Listening");
}
Error:
(base) PS C:\Users\mespi\Projects\solana-test\test> dart run
Building package executable...
Built test:test.
token account -> 7v3sr8EyiU65wDLwkvezDWVLQBDXrVZT8Mte8xnSpGSG
Listening
Unhandled exception:
FormatException: Invalid base64 data (at character 6)
error: data too large for bs58 encoding
^
#0 Base64Codec.normalize (dart:convert/base64.dart:151:7)
#1 new AccountData._fromBase64String (package:solana/src/rpc/dto/account_data/account_data.dart:22:31)
#2 new AccountData.fromJson (package:solana/src/rpc/dto/account_data/account_data.dart:73:26)
#3 _$AccountFromJson (package:solana/src/rpc/dto/account.g.dart:12:55)
#4 new Account.fromJson (package:solana/src/rpc/dto/account.dart:18:7)
#5 _$$AccountNotificationFromJson.<anonymous closure> (package:solana/src/subscription_client/notification_message.g.dart:22:30)
#6 _$NotificationParamsFromJson.<anonymous closure> (package:solana/src/subscription_client/notification_params.g.dart:15:71)
#7 _$NotificationResultFromJson (package:solana/src/subscription_client/notification_result.g.dart:16:23)
#8 new NotificationResult.fromJson (package:solana/src/subscription_client/notification_result.dart:17:7)
#9 _$NotificationParamsFromJson (package:solana/src/subscription_client/notification_params.g.dart:14:34)
#10 new NotificationParams.fromJson (package:solana/src/subscription_client/notification_params.dart:16:7)
#11 _$$AccountNotificationFromJson (package:solana/src/subscription_client/notification_message.g.dart:20:34)
#12 new _$AccountNotification.fromJson (package:solana/src/subscription_client/notification_message.freezed.dart:360:7)
#13 _$NotificationMessageFromJson (package:solana/src/subscription_client/notification_message.freezed.dart:19:34)
#14 new NotificationMessage.fromJson (package:solana/src/subscription_client/notification_message.dart:41:7)
#15 new SubscriptionMessage.fromJson (package:solana/src/subscription_client/abstract_message.dart:15:34)
#16 SubscriptionClient._parse (package:solana/src/subscription_client/subscription_client.dart:258:34)
#17 SubscriptionClient._subscribe.<anonymous closure>.<anonymous closure> (package:solana/src/subscription_client/subscription_client.dart:214:27)
#18 _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10)
#19 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#20 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#21 _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:377:25)
#22 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:244:5)
#23 _AsBroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:474:11)
#24 _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10)
#25 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#26 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#27 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
#28 _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253:10)
#29 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
#30 _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10)
#31 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#32 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#33 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
#34 _StreamController._add (dart:async/stream_controller.dart:648:7)
#35 _StreamController.add (dart:async/stream_controller.dart:596:5)
#36 new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1144:21)
#37 _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10)
#38 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#39 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#40 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
#41 _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
#42 _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:332:23)
#43 _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:226:46)
#44 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#45 _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10)
#46 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#47 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#48 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
#49 _StreamController._add (dart:async/stream_controller.dart:648:7)
#50 _StreamController.add (dart:async/stream_controller.dart:596:5)
#51 _Socket._onData (dart:io-patch/socket_patch.dart:2314:41)
#52 _RootZone.runUnaryGuarded (dart:async/zone.dart:1618:10)
#53 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#54 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#55 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
#56 _StreamController._add (dart:async/stream_controller.dart:648:7)
#57 _StreamController.add (dart:async/stream_controller.dart:596:5)
#58 _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1000:19)
#59 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
#60 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
#61 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426:5)
#62 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
By looking at the docs I see that it returns the data in base58 by default and subscribeAccount doesn't pass the optional base64 either, so, the data is received in base58, but, looks like the data is too big?. Idk, anyway, it tries to decode it with base64 in here.
I added the encoded
field with base64
manually:
Stream<Account> accountSubscribe(
String address, {
Commitment? commitment,
}) =>
_subscribe<Account>(
'account',
params: <dynamic>[
address,
if (commitment != null)
<String, String>{
'commitment': commitment.value,
'encoding': 'base64',
},
],
);
And now looks like works fine:
(base) PS C:\Users\mespi\Projects\solana-test\test> dart run
Building package executable...
Built test:test.
token account -> 7v3sr8EyiU65wDLwkvezDWVLQBDXrVZT8Mte8xnSpGSG
Listening
Instance of 'Account' # <-- now, the changes are received
Looks like an easy fix, but, this doesn't happen with SystemProgram accounts, so, I might be doing something wrong.
thanks :)) awesome work btw 💪🏻
@marc2332 Hi Marc! Do you have a telegram? I was thinking we could chat about the library and also your projects on Solana.
@marc2332 Hi Marc! Do you have a telegram? I was thinking we could chat about the library and also your projects on Solana.
Sure! I am @mkenzo_8
:)
We've just created a discord channel https://discord.gg/28h8KCF2
im getting the same issue
Same issue but for another project.
https://github.com/solana-labs/solana/blob/8ad125d0c0688aaf2b62bb95b535ff988ed7f9ac/account-decoder/src/lib.rs#L102
https://github.com/solana-labs/solana/pull/11474