Ich frage mich, ob es ein Äquivalent zu getrawtransaction von bitcoind gibt, dh einen Befehl zum Ablegen einer Rohtransaktion im Hex-Format unter Berücksichtigung ihrer Hash-ID.
Ich arbeite vorzugsweise in Geth.
Es gibt eth.getRawTransaction(<txhash>)
jetzt.
Bearbeiten : Bitte überprüfen Sie, ob Sie eine aktuelle Version von geth verwenden. Es ist Teil der aktuellen Version (v.1.8.6) und wurde vor einiger Zeit eingeführt. Sie können es auch im Quellcode sehen: https://github.com/ethereum/go-ethereum/blob/ca64a122d33008c155c35a9d0e78cfbcafb1820a/internal/web3ext/web3ext.go (suchen Sie nach getRawTransaction
)
https://github.com/ethereum/go -ethereum/blob/ec8ee611caefb5c5ad5d796178e94c1919260df4/internal/ethapi/api.go (suchen Sie nach GetRawTransactionByHash
)
Eingabe: Transaktions-Hash
Ausgabe: Bytes der entsprechenden Transaktion
Es gibt eine "undokumentierte" Methode eth_getRawTransactionByHash
von JSON-RPC
curl -H "Content-Type: application/json" -X POST --data \
'{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":["<TX_HASH>"],"id":1}' http://localhost:8545
<TX_HASH> - Transaktions-ID
Schauen Sie sich getTransactionByHash() der JSON-RPC-API an.
eth_getTransactionByHash
Returns the information about a transaction requested by transaction hash.
Parameters
DATA, 32 Bytes - hash of a transaction
params: [
"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
]
Returns
Object - A transaction object, or null when no transaction was found:
hash: DATA, 32 Bytes - hash of the transaction.
nonce: QUANTITY - the number of transactions made by the sender prior to this one.
blockHash: DATA, 32 Bytes - hash of the block where this transaction was in. null when its pending.
blockNumber: QUANTITY - block number where this transaction was in. null when its pending.
transactionIndex: QUANTITY - integer of the transactions index position in the block. null when its pending.
from: DATA, 20 Bytes - address of the sender.
to: DATA, 20 Bytes - address of the receiver. null when its a contract creation transaction.
value: QUANTITY - value transferred in Wei.
gasPrice: QUANTITY - gas price provided by the sender in Wei.
gas: QUANTITY - gas provided by the sender.
input: DATA - the data send along with the transact
Sie können das Rohtransaktions-Hex auch auf etherscan.io finden, indem Sie zu einer Transaktion gehen, Tools & Utilities
auswählen und auswählen Get Raw TxHash
. Siehe zum Beispiel:
https://etherscan.io/getRawTx?tx=0x248b16e4cb8a624ab4bb3125a3a2cf6bd6d21200b773e3d9c1f0738b1b09dd22
Wenn Sie dies programmatisch mit tun möchten, stelle ich geth
hier eine Lösung dafür vor: Kann ich die Rohtransaktion mit Nethereum abrufen?
In Python kannst du das so machen:
import web3
from eth_account._utils.legacy_transactions import (
encode_transaction,
serializable_unsigned_transaction_from_dict,
)
w3 = web3.Web3(web3.HTTPProvider("https://eth-mainnet.alchemyapi.io/v2/XXXXXXXXXXXXXXXXXXXXXXXXXXX"))
hash = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
tx = w3.eth.getTransaction(hash)
def recover_raw_transaction(tx):
"""Recover raw transaction for replay.
Inspired by: https://github.com/ethereum/eth-account/blob/1d26f44f6075d6f283aeaeff879f4508c9a228dc/eth_account/_utils/signing.py#L28-L42
"""
transaction = {
"chainId": tx["chainId"],
"nonce": int(tx["nonce"], 16),
"maxPriorityFeePerGas": int(tx["maxPriorityFeePerGas"], 16),
"maxFeePerGas": int(tx["maxFeePerGas"], 16),
"gas": int(tx["gas"], 16),
"to": Web3.toChecksumAddress(tx["to"].lower()),
"value": int(tx["value"], 16),
"accessList": tx["accessList"],
}
if "data" in tx:
transaction["data"] = tx["data"]
if "input" in tx:
transaction["data"] = tx["input"]
v = int(tx["v"], 16)
r = int(tx["r"], 16)
s = int(tx["s"], 16)
unsigned_transaction = serializable_unsigned_transaction_from_dict(transaction)
return "0x" + encode_transaction(unsigned_transaction, vrs=(v, r, s)).hex()
raw_tx = recover_raw_transaction(tx)
Wenn einige grundlegende Felder access_list
fehlen, wie z. B. bei der erneuten Übertragung per Hash, fügen Sie sie manuell hinzu.
Taywano
Blues
rostig
eth.getRawTransaction()
. Worüber redest du?Thorkil Værge