gpt4 book ai didi

javascript - 如何通过交易哈希知道交易中使用的加密货币?

转载 作者:行者123 更新时间:2023-12-05 00:38:52 25 4
gpt4 key购买 nike

如何通过交易哈希知道交易中使用的加密货币?
我正在使用以下代码:

<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>

...

if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

var transaction = web3.eth.getTransaction('0x42ca92e05d21592e92e36c93ae6e31d0583c4c95cadd42901e297b55c6b465af');
console.log(transaction);
我得到下面的对象:
Promise
[[Prototype]]: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Object
blockHash: "0x91a5799cac3de01498a4988d4e55bb29f6b56617490bf854ce5e1f21821db2e2"
blockNumber: 14832362
from: "0xdE4429D4cD2afa9C4314254F1cb074181f0e184e"
gas: 200000
gasPrice: "10000000000"
hash: "0x42ca92e05d21592e92e36c93ae6e31d0583c4c95cadd42901e297b55c6b465af"
input: "0x"
nonce: 12
r: "0xec1cb9f6b134c375542c4aaff07aa6ae8bd831918e52a609e77f227683524f67"
s: "0x798123f2eb75584430c2016cf91eeb384306291dcbc50eae64fc73c140cc972d"
to: "0x69AF47261C4585C365e4E1D93b635974a30fb117"
transactionIndex: 7
type: 0
v: "0x94"
value: "10000000000000000"
[[Prototype]]: Object

我找到了值(value)、收件人和来源,但我不知道关于使用 token 的任何信息在哪里。
如果有人帮助我,我会很高兴。

最佳答案

我不认为你可以从交易哈希中得到它:这是交易哈希的分解:

0x
// https://eth.wiki/fundamentals/rlp for more on f8
// 0xf8-0xf7=1byte=2 chars which tells you next 2 chars is the length of the paylaod
f8
// length of payload. 0x69=105bytes=210 chars.
69
// Nonce. 1byte
12
//0x85-0x80=133-128= 5bytes=10chars= GAS PRICE
85 012a05f200
// 0x83-0x80=131-128=3bytes=6chars= GAS LIMIT
83 07a120
// 0x94 - 0x80=148-128=20bytes=40chars= TO
94 b75fe87f44cb2003f3472424261f021d2100ce5a
// this should be value. empty valu, string is represended as 80
80
// 0x84-0x80=132-128=4bytes=8 chars= DATA
84 3ccfd60b
// "v" value. 1byte
2a
// a0-0x80=160-128=32 bytes=64 chars= "r" VALUE
a0 fce2a70cde55dc86a203d2387469c36da00e9a9f3536b867f6761c314b1f1423
// a0-0x80=160-128=32 bytes=64 chars= "s" VALUE
a0 7b85742fd48a687b8daa097d1fb9d4b5135de6deb5b6fd16dd0f28d6c28727b6

To get an ERC20 transfer's information, you need the transactionreceipt, since transfer information is recorded in a transfer eventlog. You should be using eth_getTransactionReceipt.


这篇文章解释了如何从 transaction_receipt 获取它。 :
ERC20 Tokens Transferred Information from Transaction Hash

关于javascript - 如何通过交易哈希知道交易中使用的加密货币?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70935158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com