繁体   English   中英

如何从solana交易签名中获取发送方和接收方的钱包ID?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM