Home Eth使用rawtransaction创建转账eth,转账token的过程,erc20归拢
Post
Cancel

Eth使用rawtransaction创建转账eth,转账token的过程,erc20归拢

参考:

这个文章有入门线索: https://ethereum.stackexchange.com/questions/3386/create-and-sign-offline-raw-transactions

确认了线索: https://ethereum.stackexchange.com/questions/43980/how-to-transfer-ethereum-from-one-account-to-another-using-address-and-password

api:  https://web3js.readthedocs.io/en/v1.2.0/web3-eth-accounts.html#signtransaction

这个脚本是用来根据 keystore, secret 获得 signed tx的:https://gist.github.com/neuhaus/7387edf411513a9f11f1242dcec8d62e

这个是nodejs版本的转账erc-20:  https://ethereum.stackexchange.com/questions/24828/how-to-send-erc20-token-using-web3-api

这个是另一个nodejs的ETH转账:https://medium.com/blockchain-musings/how-to-create-raw-transactions-in-ethereum-part-1-1df91abdba7c

注意:最新的eth-js 包:https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/tx

ETH版本的第三方包: https://github.com/se3000/ruby-eth

1。 只具有address, secret是不够的,还需要 private key. 

2. 使用private key 做签名,得到 signed tx

3. 使用这个signed tx 作为参数, 就可以发送了。

目前研究了2个lib, 一个是ruby, 一个是node,都可以使用。

关键在于正确的node

可以不搭建 ETH全节点, 使用 infura来进行接口的调用。 

https://infura.io/docs/ethereum/json-rpc/eth-sendRawTransaction

例子:

curl https://mainnet.infura.io/v3/6d5b3edb39ed4ac39731a6f107540942     -X POST     -H "Content-Type: application/json"     -d '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0xf86c82039585174876e800825208943ae7a18407b17037b2ecc4901c1b77db98367cda866d23ad5f80008026a085b81f23b7e80c65f6e8d97f2c6482c0cc7d660fc538f566c47c22e57c841726a07351fe455188b160c726d3032d03ddcdf1929716bb1c5aa06274fdf2830b73ba"],"id":1}'

结果:
{"jsonrpc":"2.0","id":1,"result":"0x371c92a5815a734c6cd4c6e890e4b9216aa9eeee482b6a8279bea1bdeebc0d2d"}

https://infura.io/docs/ethereum/json-rpc/eth-getTransactionCount

例子:

curl https://mainnet.infura.io/v3/6d5b3edb39ed4ac39731a6f107540942     -X POST     -H "Content-Type: application/json"     -d '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params": ["0x7CCfaF74ADBA37b2eF11B4caa3ce37597074c45c","latest"],"id":1}'

可以查到是

{"jsonrpc":"2.0","id":1,"result":"0x396"}       # => 918 0

.

This post is licensed under CC BY 4.0 by the author.