You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have encountered a bug that occurs probabilistically. I want to send a transaction containing multiple instructions to the blockchain. Although I can successfully call
and get a transaction ID, I sometimes find that the transaction is dropped by the Solana cluster when I search for it on the blockchain. What could be the reason?
The instructions in my transaction include:
Compute Budget: SetComputeUnitPrice
Compute Budget: SetComputeUnitLimit
Token Program: TransferChecked
Token Program: TransferChecked
System Program: Transfer
Here is my code:
funcTestMultiInstructionTransfer(t*testing.T) {
rpcClient:=rpc.New(RpcUrl)
rewardPrivKey:=solana.MustPrivateKeyFromBase58(MainPrivate)
alicePrivateKey:=solana.MustPrivateKeyFromBase58(AlicePrivate)
rewardPubKey:=rewardPrivKey.PublicKey()
alicePubKey:=solana.MustPublicKeyFromBase58(AliceNativePubKey)
bobPubKey:=solana.MustPublicKeyFromBase58(BobNativePubKey)
dexPubKey, _:=solana.PublicKeyFromBase58(DexNativePubKey)
// get token accounttokenMintAccount:=solana.MustPublicKeyFromBase58(TokenMintAddress)
rewardTokenAccount, err:=GetSPLTokenAccountByNative(rpcClient, rewardPubKey, tokenMintAccount)
iferr!=nil {
panic(err)
}
fmt.Printf("get reward token account %v \n", rewardTokenAccount)
aliceTokenAccount, err:=GetSPLTokenAccountByNative(rpcClient, alicePubKey, tokenMintAccount)
iferr!=nil {
panic(err)
}
fmt.Printf("get to token account of alice %v \n", aliceTokenAccount)
bobTokenAccount, err:=GetSPLTokenAccountByNative(rpcClient, bobPubKey, tokenMintAccount)
iferr!=nil {
panic(err)
}
fmt.Printf("get to token account of bob %v \n", bobTokenAccount)
amount:=uint64(1100000)
rewardAmount:=uint64(1100000) *2// ComputeBudget111111111111111111111111111111computeBudgetPriceInst:=computebudget.NewSetComputeUnitPriceInstructionBuilder().
SetMicroLamports(100000).
Build()
// ComputeBudget111111111111111111111111111111computeBudgetLimitInst:=computebudget.NewSetComputeUnitLimitInstructionBuilder().
SetUnits(600000).
Build()
// 添加多条指令// 1.transfer token to bobtransferInst:=token.NewTransferCheckedInstructionBuilder().
SetAmount(amount).
SetDecimals(6).
SetSourceAccount(*aliceTokenAccount).
SetMintAccount(tokenMintAccount).
SetDestinationAccount(*bobTokenAccount).
SetOwnerAccount(alicePubKey).
Build()
// 2.reward token to alicerewardInst:=token.NewTransferCheckedInstructionBuilder().
SetAmount(rewardAmount).
SetDecimals(6).
SetSourceAccount(*rewardTokenAccount).
SetMintAccount(tokenMintAccount).
SetDestinationAccount(*aliceTokenAccount).
SetOwnerAccount(rewardPubKey).
Build()
// 3.send sol to dextoDexInst:=system.NewTransferInstructionBuilder().
SetLamports(2250000).
SetFundingAccount(alicePubKey).
SetRecipientAccount(dexPubKey).
Build()
// get recent block hashrecent, err:=rpcClient.GetRecentBlockhash(context.Background(), rpc.CommitmentFinalized)
iferr!=nil {
panic(err)
}
fmt.Printf("recent block hash is %v\n", recent.Value.Blockhash)
// construct a transaction to estimate gas feetx0, err:=solana.NewTransaction(
[]solana.Instruction{
computeBudgetPriceInst,
computeBudgetLimitInst,
transferInst,
rewardInst,
toDexInst,
},
recent.Value.Blockhash,
solana.TransactionPayer(alicePubKey),
)
iferr!=nil {
panic(err)
}
messageContent0, err:=tx0.Message.MarshalBinary()
iferr!=nil {
panic(err)
}
base64EncodeMsg:=base64.StdEncoding.EncodeToString(messageContent0)
feeResult, err:=rpcClient.GetFeeForMessage(context.Background(), base64EncodeMsg, rpc.CommitmentConfirmed)
iferr!=nil {
panic(err)
}
fmt.Printf("get message fee %v\n", *feeResult.Value)
// send gas fee & 2 to dextoDexInst=system.NewTransferInstructionBuilder().
SetLamports(*feeResult.Value*2).
SetFundingAccount(alicePubKey).
SetRecipientAccount(dexPubKey).
Build()
// construct the final transaction to send to blockchaintx, err:=solana.NewTransaction(
[]solana.Instruction{
computeBudgetPriceInst,
computeBudgetLimitInst,
transferInst,
rewardInst,
toDexInst,
},
recent.Value.Blockhash,
solana.TransactionPayer(alicePubKey),
)
iferr!=nil {
panic(err)
}
// sign transaction_, err=tx.Sign(
func(key solana.PublicKey) *solana.PrivateKey {
ifkey.Equals(alicePubKey) {
return&alicePrivateKey
}
ifkey.Equals(rewardPubKey) {
return&rewardPrivKey
}
returnnil
})
iferr!=nil {
panic(err)
}
// get transaction sig and print ittxSig, err:=rpcClient.SendTransaction(context.Background(), tx)
fmt.Printf("https://solscan.io/tx/%s\n", txSig)
}
The text was updated successfully, but these errors were encountered:
Hello, I have encountered a bug that occurs probabilistically. I want to send a transaction containing multiple instructions to the blockchain. Although I can successfully call
and get a transaction ID, I sometimes find that the transaction is dropped by the Solana cluster when I search for it on the blockchain. What could be the reason?
The instructions in my transaction include:
Here is my code:
The text was updated successfully, but these errors were encountered: