首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我签署的交易似乎失败了,而且没有广播。为什么?

我签署的交易似乎失败了,而且没有广播。为什么?
EN

Ethereum用户
提问于 2020-12-20 09:13:55
回答 1查看 419关注 0票数 1

我想做一个非常简单的操作:将eth发送到另一个地址。

以下是我所做的:

方法1.使用personal.send_transaction JSON接口。(似乎不推荐)

我跑:

代码语言:javascript
复制
curl --request POST   --data '{
    "jsonrpc":"2.0",
    "method":"personal_sendTransaction",
    "params":[
      {
        "gas": "0x5208",
        "gasPrice": "0x178411b200",
        "from": "0x7CCfaF74ADBA37b2eF11B4caa3ce3759xxxxxxxx",
        "to": "0x3Ae7a18407B17037B2ECC4901c1b77Dbxxxxxxxx",
        "value": "0x4f94ae6af8000"
      },
      "my_pass_word"
    ],
    "id": 4004
  }'   --header 'Content-Type: application/json' http://172.16.1.53:8800

答复:

代码语言:javascript
复制
{
    "jsonrpc":"2.0",
    "result":"0x76af9bc26ac39f6011c76c3adf2914ab8b677ad95a8687ed0b3de058d4866bb6",
    "id":4004
}

然而,在以太扫描中不能找到这种tx。

得到了这张日志:

代码语言:javascript
复制
2020-12-20 07:45:03 UTC http.worker10 WARN rpc  personal_sendTransaction is deprecated and will be removed in future versions: Account management is being phased out see #9997 for alternatives.
2020-12-20 07:45:03 UTC http.worker10 DEBUG own_tx  Imported to the pool (hash 0x76af9bc26ac39f6011c76c3adf2914ab8b677ad95a8687ed0b3de058d4866bb6)
2020-12-20 07:45:03 UTC http.worker10 DEBUG txqueue  [0x76af9bc26ac39f6011c76c3adf2914ab8b677ad95a8687ed0b3de058d4866bb6] Added to the pool.
2020-12-20 07:45:03 UTC http.worker10 DEBUG txqueue  [0x76af9bc26ac39f6011c76c3adf2914ab8b677ad95a8687ed0b3de058d4866bb6] Sender: 0x7ccf…xxxx, nonce: 887, gasPrice: 101000000000, gas: 21000, value: 1400000000000000, dataLen: 0))
2020-12-20 07:45:03 UTC IO Worker #1 DEBUG sync  Finished transaction propagation, took 0ms
2020-12-20 07:45:03 UTC http.worker10 DEBUG txqueue  Re-computing pending set for block: 11475896
2020-12-20 07:45:03 UTC http.worker10 DEBUG miner  Attempting to push 1 transactions.
2020-12-20 07:45:03 UTC http.worker10 DEBUG miner  Adding tx 0x76af9bc26ac39f6011c76c3adf2914ab8b677ad95a8687ed0b3de058d4866bb6 took 3 ms
2020-12-20 07:45:03 UTC http.worker10 DEBUG miner  Pushed 1 transactions in 3 ms
2020-12-20 07:45:03 UTC http.worker10 DEBUG rpc  [Some(Num(4004))] Took 42ms
2020-12-20 07:45:03 UTC http.worker10 DEBUG rpc  Response: {"jsonrpc":"2.0","result":"0x76af9bc26ac39f6011c76c3adf2914ab8b677ad95a8687ed0b3de058d4866bb6","id":4004}.

方法2.将eth_sendRawTransaction调用到本地ETH节点.

我按照以下步骤做了这件事:

步骤2.1获得了私钥(非常正确,我保证,我是通过2语言API获得的,它们是一样的!)

代码语言:javascript
复制
<my_private_key>

步骤2.2通过我的代码获得了签名的tx:

代码语言:javascript
复制
const get_raw_tx = function(params){

  console.info("== params:")
  console.info(params)
  const privateKey = Buffer.from(
    params.private_key,
    'hex',
  )

  const txParams = { 
    nonce: params.nonce,
    gasPrice: params.gas_price,
    gasLimit: params.gas_limit,
    to: params.to_address,
    value: params.crypto_amount,
    data: params.data,
  }

  const tx = new EthereumTx(txParams, { chain: 'mainnet', hardfork: 'petersburg' })
  tx.sign(privateKey)
  const serializedTx = tx.serialize()
  const rawTx = '0x' + serializedTx.toString('hex');
  return rawTx
}

和HTTP方法:

  • crypto_amount: 0.0013 ETH
  • gas_limit: 21000,十六进制: 0x5208
  • gas_price: 121000000000 ( 121千兆),十六进制: 0x1c2c297a00
代码语言:javascript
复制
$ curl http://localhost:8000/get_tx?private_key=MY_PRIVATE_KEY&nonce=0x01&gas_price=0x1c2c297a00&gas_limit=0x2710&to_address=0xC6d64494D2042B69aceAd368395f8e4Fxxxxxxxx&crypto_amount=1300000000000000

得到一个签名的TX字符串:

代码语言:javascript
复制
0xf86d820d1b851c2c297a00825208943ae7a18407b17037b2ecc4901c1b77db98367cda87049e57d63540008026a07931b78f0f596f49655d2c0418156f742ffab64cb2c545616d1f3843e4f4f778a026d63f88d6166ec32223c1e850fb9245e4b5df6d50237080684fc933e7ac0e4b

步骤2.3我进行了如下JSON-调用:

代码语言:javascript
复制
curl --location --request POST 'http://my-server-ip:port'   --header 'Content-Type: application/json'   --data-raw '{
    "jsonrpc":"2.0",
    "method":"eth_sendRawTransaction",
    "params":["0xf86d820d1b851c2c297a00825208943ae7a18407b17037b2ecc4901c1b77db98367cda87049e57d63540008026a07931b78f0f596f49655d2c0418156f742ffab64cb2c545616d1f3843e4f4f778a026d63f88d6166ec32223c1e850fb9245e4b5df6d50237080684fc933e7ac0e4b"],
    "id": 4004
  }'

以下是我们的回应:

代码语言:javascript
复制
{
    "jsonrpc":"2.0",
    "result":"0x06a1958e25ef269346cc79043c4c4343b9df86bf0b135c257b9b7077e7d83bc7",
    "id":4004
}

在( http://etherscan.io/tx/0x06a1958e25ef269346cc79043c4c4343b9df86bf0b135c257b9b7077e7d83bc7 )上仍然找不到这个tx

日志中没有错误或警告。

方法3.称为呋喃API

代码语言:javascript
复制
curl https://mainnet.infura.io/v3/MY-PROJECT-ID     
    -X POST
    -H "Content-Type: application/json"
    -d '{
         "jsonrpc":"2.0",
         "method":"eth_sendRawTransaction",
         "params":["0xf86d820d1b851c2c297a00825208943ae7a18407b17037b2ecc4901c1b77db98367cda87049e57d63540008026a07931b78f0f596f49655d2c0418156f742ffab64cb2c545616d1f3843e4f4f778a026d63f88d6166ec32223c1e850fb9245e4b5df6d50237080684fc933e7ac0e4b"],
         "id":1
       }'

从呋喃那里得到了回应:

代码语言:javascript
复制
{
    "jsonrpc":"2.0",
    "id":1,
    "result":"0x5809db5cdbdab054ca7f5f383e59ba6df74e3f5e87a33b90df1b1c6e7d0ae587"
}

不过,在etherscan.io上找不到这个TX。

那么,谁能帮我,为什么所有这些方法都失败了。

非常感谢!

附注:

我的环境

Ubuntu 18.04服务器

客户:蛋白石( OpenEthereum/v3.0.1-stable-8ca8089-20200601/x86_64-unknown-linux-gnu/rustc1.43.1 )

命令启动它:nohup ./openethereum &

配置文件:(在.local/share/openethereum/config.toml中)

代码语言:javascript
复制
[parity]
mode = "active"
identity = "lueluelue"
[rpc]
apis = ["web3", "eth", "pubsub", "net", "parity", "parity_pubsub", "traces", "rpc", "shh", "shh_pubsub", "personal", "parity_accounts", "secretstore"]
server_threads = 2

port = 8800
interface = "172.my.i.p"

[websockets]
apis = ["web3", "eth", "pubsub", "net", "parity", "parity_pubsub", "traces", "rpc", "shh", "shh_pubsub", "personal"]

[misc]
log_file = "/home/ubuntu/eth.log"
logging = "debug"

[mining]
min_gas_price = 1 

当块未完成同步时,我运行JSON调用。(同步至1天前)

EN

回答 1

Ethereum用户

回答已采纳

发布于 2020-12-24 09:50:47

好的,我明白了:参数nonce很重要!

我的错误是:我随机地给出了nonce参数,这在某种程度上是无效的。(我不知道)

在搜索了许多帖子之后,我发现nonce是很重要的!(根据https://nonseodion.medium.com/7-easy-steps-to-resolve-cancel-pending-ethereum-transactions-88d7d8bce053的说法,这篇文章谈到了现在和pending事务之间的关系)

还有这篇文章:https://info.etherscan.com/how-to-cancel-ethereum-pending-transactions提到了现在。

因此,为了弄清楚哪个数字应该是我的地址,我使用MetaMask创建了一个事务,很快,我得到了它的状态:

代码语言:javascript
复制
0.204465275198051046 Eth
Nonce: 912

0.202643275198051046 Eth
Nonce: 913     <!---  this should be your next transaction's nonce! 

因此,我更改了我的代码,指定了正确的nonce,然后我的新签名的事务广播了3秒!

^_^

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/91324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档