[英]How to get a token mint address from a transaction signature in Solana web3
[英]How to get the wallet ID of sender and receiver from solana transaction signature?
我有 Solana 交易的簽名,我想找到發送方和接收方的錢包 ID。 這就是我所做的:
const connection = new Web3.Connection(Web3.clusterApiUrl("devnet"), "confirmed");
const transaction = await connection.getTransaction(signature);
當我執行console.log(transaction)
時,它有blockTime
等字段,但to
from
地址。 有人可以幫忙嗎?
當調用getTransaction
時,節點將以指定的格式返回交易。 默認情況下, connection.getTransaction
將返回帶有 base58 編碼的事務,因此請嘗試改用connection.getParsedTransaction
。 這是一個簡單傳輸的示例:
curl https://api.devnet.solana.com -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getTransaction",
"params": [
"2YHDUWRRh4jwaAqSPJqCiu97FTy6Pu2C6XGbAzsaBbyjQeXW11z
hhF3DJHt4vDFHVND1ybdSHf6E5FxbjFXZP4gQ",
"jsonParsed"
]
}
' | python3 -m json.tool
{
"jsonrpc": "2.0",
"result": {
"blockTime": 1647001173,
"meta": {
"err": null,
"fee": 5000,
"innerInstructions": [],
"logMessages": [
"Program 11111111111111111111111111111111 invoke [1]",
"Program 11111111111111111111111111111111 success"
],
"postBalances": [
23932341357,
110000000,
1
],
"postTokenBalances": [],
"preBalances": [
23942346357,
100000000,
1
],
"preTokenBalances": [],
"rewards": [],
"status": {
"Ok": null
}
},
"slot": 120237987,
"transaction": {
"message": {
"accountKeys": [
{
"pubkey": "4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn",
"signer": true,
"writable": true
},
{
"pubkey": "4AUt2JyjzJYVhWkjKugXmzhWizpb4SpLHBtL2fuqPskU",
"signer": false,
"writable": true
},
{
"pubkey": "11111111111111111111111111111111",
"signer": false,
"writable": false
}
],
"instructions": [
{
"parsed": {
"info": {
"destination": "4AUt2JyjzJYVhWkjKugXmzhWizpb4SpLHBtL2fuqPskU",
"lamports": 10000000,
"source": "4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn"
},
"type": "transfer"
},
"program": "system",
"programId": "11111111111111111111111111111111"
}
],
"recentBlockhash": "3zny2xt5wimev9Jry3TiAyK8yA2pMMcGvsPWpFN5HiL6"
},
"signatures": [
"2YHDUWRRh4jwaAqSPJqCiu97FTy6Pu2C6XGbAzsaBbyjQeXW11zhhF3DJHt4vDFHVND1ybdSHf6E5FxbjFXZP4gQ"
]
}
},
"id": 1
}
在result.transaction.message.instructions[0].parsed
你會得到你想要的。
有關getTransaction
調用的更多信息,請訪問https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.