TransactionReceipt has empty children array for PrivateKey.fromStringECDSA() but not for PrivateKey.generateECDSA()

huangapple go评论73阅读模式
英文:

TransactionReceipt has empty children array for PrivateKey.fromStringECDSA() but not for PrivateKey.generateECDSA()

问题

当我运行未经修改的代码示例transfer-using-evm-address.js时,它可以正常运行。

然而,当我将这行代码:

const privateKey = PrivateKey.generateECDSA();

更改为:

const privateKey = PrivateKey.fromStringECDSA(process.env.TARGET_HEX_PRIVATE_KEY);

脚本会抛出意外错误。除了私钥是随机生成的,而不是从输入字符串设置之外,实际上没有任何区别。

为什么会发生这种情况?如何纠正?

值得注意的是,转账确实成功,账户余额增加,我可以在钱包(MetaMask)和区块浏览器0.0.3996359中看到。

然而,尝试从MetaMask内部执行HBAR交易失败,因此似乎确实需要执行其余步骤。

详细信息:

输出 #1 - 用于PrivateKey.generateECDSA()

% node ./transfer-using-evm-address.js
Private key: 3030020100300706052b8104000a042204205972cfade03879583d2a30a8013b07a4b2a6d6497ef4454a1be9bfd70e6e29e7
Public key: 302d300706052b8104000a032200023cd10457c01d01db85467d587c7d31f29bd147f2213f9727d91fadb7fb2cc405
Corresponding evm address: 144daf7b20f09b468e18f29e72c1f166a2bf0447
TransactionReceipt {
  status: Status { _code: 22 },
  accountId: null,
  fileId: null,
  contractId: null,
  topicId: null,
  tokenId: null,
  scheduleId: null,
  exchangeRate: ExchangeRate {
    hbars: 30000,
    cents: 195739,
    expirationTime: 2023-04-06T16:00:00.000Z,
    exchangeRateInCents: 6.524633333333333
  },
  topicSequenceNumber: Long { low: 0, high: 0, unsigned: false },
  topicRunningHash: Uint8Array(0) [],
  totalSupply: Long { low: 0, high: 0, unsigned: false },
  scheduledTransactionId: null,
  serials: [],
  duplicates: [],
  children: [
    TransactionReceipt {
      status: [Status],
      accountId: [AccountId],
      fileId: null,
      contractId: null,
      topicId: null,
      tokenId: null,
      scheduleId: null,
      exchangeRate: null,
      topicSequenceNumber: [Long],
      topicRunningHash: Uint8Array(0) [],
      totalSupply: [Long],
      scheduledTransactionId: null,
      serials: [],
      duplicates: [],
      children: []
    }
  ]
}
Account ID of the newly created account: 0.0.3999408
Account 0.0.3999408 does not have public key, therefore it is a hollow account
HAPI transaction status: SUCCESS
The public key of the newly created and now complete account: 302d300706052b8104000a032200023cd10457c01d01db85467d587c7d31f29bd147f2213f9727d91fadb7fb2cc405

输出 #2 - 用于PrivateKey.fromStringECDSA(...)

% node ./transfer-using-evm-address.js
Private key: 3030020100300706052b8104000a04220420fb11afc5d508036ac7a9df9f1eb7cea551e4a7b738c2c70da099fe5f379f3364
Public key: 302d300706052b8104000a032200027a753c29cc9f0ea0b6ccf0614676daeba3da0dbd5f54ef9850ad3878ded4e077
Corresponding evm address: 07ffaadfe3a598b91ee08c88e5924be3eff35796
TransactionReceipt {
  status: Status { _code: 22 },
  accountId: null,
  fileId: null,
  contractId: null,
  topicId: null,
  tokenId: null,
  scheduleId: null,
  exchangeRate: ExchangeRate {
    hbars: 30000,
    cents: 195739,
    expirationTime: 2023-04-06T16:00:00.000Z,
    exchangeRateInCents: 6.524633333333333
  },
  topicSequenceNumber: Long { low: 0, high: 0, unsigned: false },
  topicRunningHash: Uint8Array(0) [],
  totalSupply: Long { low: 0, high: 0, unsigned: false },
  scheduledTransactionId: null,
  serials: [],
  duplicates: [],
  children: []
}
file:///Users/user/code/hedera/hedera-scratch/transfer-using-evm-address.js:102
    const newAccountId = receipt.children[0].accountId.toString();
                                             ^

TypeError: Cannot read properties of undefined (reading 'accountId')
    at main (file:///Users/user/code/hedera/hedera-scratch/transfer-using-evm-address.js:102:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.15.0
英文:

When I run the code example for transfer-using-evm-address.js, unmodified, it works.

However, when I change this line:

    const privateKey = PrivateKey.generateECDSA();

to this:

    const privateKey = PrivateKey.fromStringECDSA(process.env.TARGET_HEX_PRIVATE_KEY);

the script throws an unexpected error. There is literally no difference apart from the private key being randomly generated, versus the private key being set from an input string.

Why is this occurring? How to rectify?

For the record, the transfer does indeed succeed,
and the balance of the account increases,
and I can see this in the wallet (MetaMask),
as well as in the block explorer 0.0.3996359.

However, trying to perform a transfer HBAR transaction from within MetaMask fails with this account, so it seems like the remainder of the steps are indeed needed.


Details:

Output #1 - for PrivateKey.generateECDSA()

% node ./transfer-using-evm-address.js
Private key: 3030020100300706052b8104000a042204205972cfade03879583d2a30a8013b07a4b2a6d6497ef4454a1be9bfd70e6e29e7
Public key: 302d300706052b8104000a032200023cd10457c01d01db85467d587c7d31f29bd147f2213f9727d91fadb7fb2cc405
Corresponding evm address: 144daf7b20f09b468e18f29e72c1f166a2bf0447
TransactionReceipt {
  status: Status { _code: 22 },
  accountId: null,
  fileId: null,
  contractId: null,
  topicId: null,
  tokenId: null,
  scheduleId: null,
  exchangeRate: ExchangeRate {
    hbars: 30000,
    cents: 195739,
    expirationTime: 2023-04-06T16:00:00.000Z,
    exchangeRateInCents: 6.524633333333333
  },
  topicSequenceNumber: Long { low: 0, high: 0, unsigned: false },
  topicRunningHash: Uint8Array(0) [],
  totalSupply: Long { low: 0, high: 0, unsigned: false },
  scheduledTransactionId: null,
  serials: [],
  duplicates: [],
  children: [
    TransactionReceipt {
      status: [Status],
      accountId: [AccountId],
      fileId: null,
      contractId: null,
      topicId: null,
      tokenId: null,
      scheduleId: null,
      exchangeRate: null,
      topicSequenceNumber: [Long],
      topicRunningHash: Uint8Array(0) [],
      totalSupply: [Long],
      scheduledTransactionId: null,
      serials: [],
      duplicates: [],
      children: []
    }
  ]
}
Account ID of the newly created account: 0.0.3999408
Account 0.0.3999408 does not have public key, therefore it is a hollow account
HAPI transaction status: SUCCESS
The public key of the newly created and now complete account: 302d300706052b8104000a032200023cd10457c01d01db85467d587c7d31f29bd147f2213f9727d91fadb7fb2cc405

Output #2 - for PrivateKey.fromStringECDSA(...)

% node ./transfer-using-evm-address.js
Private key: 3030020100300706052b8104000a04220420fb11afc5d508036ac7a9df9f1eb7cea551e4a7b738c2c70da099fe5f379f3364
Public key: 302d300706052b8104000a032200027a753c29cc9f0ea0b6ccf0614676daeba3da0dbd5f54ef9850ad3878ded4e077
Corresponding evm address: 07ffaadfe3a598b91ee08c88e5924be3eff35796
TransactionReceipt {
  status: Status { _code: 22 },
  accountId: null,
  fileId: null,
  contractId: null,
  topicId: null,
  tokenId: null,
  scheduleId: null,
  exchangeRate: ExchangeRate {
    hbars: 30000,
    cents: 195739,
    expirationTime: 2023-04-06T16:00:00.000Z,
    exchangeRateInCents: 6.524633333333333
  },
  topicSequenceNumber: Long { low: 0, high: 0, unsigned: false },
  topicRunningHash: Uint8Array(0) [],
  totalSupply: Long { low: 0, high: 0, unsigned: false },
  scheduledTransactionId: null,
  serials: [],
  duplicates: [],
  children: []
}
file:///Users/user/code/hedera/hedera-scratch/transfer-using-evm-address.js:102
    const newAccountId = receipt.children[0].accountId.toString();
                                             ^

TypeError: Cannot read properties of undefined (reading 'accountId')
    at main (file:///Users/user/code/hedera/hedera-scratch/transfer-using-evm-address.js:102:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.15.0

答案1

得分: 1

我使用generateECDSAfromStringECDSA两种方法测试了脚本,但未能复现问题。我猜测错误发生的原因是因为收据没有传播到SDK发送请求的节点。有可能交易被发送到了节点A,但SDK正在尝试从节点B查询收据。因此,由于某种延迟,节点可能无法定位交易,从而导致错误。请告诉我是否有可靠的方法来复现这个问题。

英文:

I tested the script using both generateECDSA and fromStringECDSA, but was unable to reproduce the problem. My guess is that the error is occurring because the receipt is not being propagated to the node that the SDK sent the request to. It's possible that the transaction was sent to Node A, but the SDK is attempting to query the receipt from Node B. As a result, the node may not be able to locate the transaction due to some delay, resulting in the error. Please let me know if you have a reliable way to reproduce the problem

huangapple
  • 本文由 发表于 2023年4月7日 00:46:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定