-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not get Tx Hash after transaction. #1656
Comments
What do you mean by Your second example is incorrect though. You cannot just encode compiled message and pass it as transaction – you need to sign it. So instead of final serializedMessage =
base64Encode(compiledMessage.toByteArray().toList()); you can try something like this final signedTx = SignedTx(
compiledMessage: compiledMessage,
signatures: [await source.sign(compiledMessage.toByteArray())],
);
final serializedMessage = signedTx.encode(); That's done under the hood by |
thankyou for your response. 1). 2). i still have issue (need help) because if i check transactionID in scanner/explorer that i got from here but method is waiting for SignatureStatus & here i got error from dart. thankyou |
@kprpl please send fully reproducible example, it would be easier to find the root cause. |
Sure here is code.
|
@kprpl I cannot reproduce any error. This is the code I tried with local validator (basically, your code with a couple of minor fixes regarding wallet generation), and it works: import 'package:solana/encoder.dart';
import 'package:solana/solana.dart';
Future<void> main() async {
SolanaClient solanaClient = SolanaClient(
rpcUrl: Uri.parse("http://127.0.0.1:8899"),
websocketUrl: Uri.parse("ws://127.0.0.1:8900"),
);
final Ed25519HDKeyPair senderWallet = await Ed25519HDKeyPair.random();
await solanaClient.requestAirdrop(
address: senderWallet.publicKey,
lamports: lamportsPerSol,
);
final Ed25519HDPublicKey receiverWallet =
(await Ed25519HDKeyPair.random()).publicKey;
await transferSolCoin(
solClient: solanaClient,
source: senderWallet,
destination: receiverWallet,
amount: 0.01,
);
}
Future<void> transferSolCoin({
required SolanaClient solClient,
required Ed25519HDKeyPair source,
required Ed25519HDPublicKey destination,
required double amount,
}) async {
try {
final int lamports = (amount * 1e9).toInt();
final instruction = SystemInstruction.transfer(
fundingAccount: source.publicKey,
recipientAccount: destination,
lamports: lamports,
);
final latestBlockhash = await solClient.rpcClient.getLatestBlockhash();
final message = Message.only(instruction);
final compiledMessage = message.compile(
recentBlockhash: latestBlockhash.value.blockhash,
feePayer: source.publicKey,
);
final signedTx = SignedTx(
compiledMessage: compiledMessage,
signatures: [await source.sign(compiledMessage.toByteArray())],
);
final serializedMessage = signedTx.encode();
final signature = await solClient.rpcClient.sendTransaction(
serializedMessage,
preflightCommitment: Commitment.finalized,
);
print("signature before waitForSignatureStatus: $signature");
await solClient.waitForSignatureStatus(
signature,
status: Commitment.finalized,
timeout: Duration(seconds: 60),
);
print("signature after waitForSignatureStatus $signature");
print("transfer success");
} catch (error) {
print("error is $error");
}
} This is the output I get:
|
I got similar behavior when using the Mainnet beta endpoint which is timeout when waiting for signature status. However, switching to Devnet would return a valid transaction ID. |
help needed
issue#1:
I am transfaring Sol with
transferLamports()
method the transaction is complete by blockchain and can see and verify on explore but can not get tx hash in returnissue#2:
I had try with lengthy way with
sendTransaction
with that i got error in return. [code is attached]To Reproduce
I have attache the code.
Expected behavior
should return tx hash in return of
transferLamports()
method so i can confirm that transaction is success.Code
The text was updated successfully, but these errors were encountered: