当我同时将 2 个智能合约部署到 Hedera Testnet 时,出现以下错误:
nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ]
Run Code Online (Sandbox Code Playgroud)
这种情况间歇性地发生,大约有 20% 的时间发生。它们的发生似乎是不确定的,尽管我无法证实这一点。
我的部署代码是:
const deploymentSigner: Signer = (await hre.ethers.getSigners())[0];
// console.log('Deployment signer address', (await deploymentSigner.getAddress()));
const scDeploymentPromises: Promise<Contract>[] = [];
for (let idx = 0; idx < scNamesToDeploy.length; ++idx) {
const scName = scNamesToDeploy[idx];
const scFactory: ContractFactory =
await hre.ethers.getContractFactory(scName);
console.log(`Deploying ${scName} on ${networkName} ...`);
const sc: Contract = await scFactory.deploy();
// NOTE deployment with constructor params not needed for these particular SCs
const …Run Code Online (Sandbox Code Playgroud) 我正在按照以下说明进行操作hedera-json-rpc-relay:具体来说docs/configuration.md,尝试运行连接到 Hedera Testnet 的 RPC 中继:
HEDERA_NETWORK=TESTNET
OPERATOR_ID_MAIN=0.0.3996280
OPERATOR_KEY_MAIN=<redacted>
OPERATOR_ID_ETH_SENDRAWTRANSACTION=
OPERATOR_KEY_ETH_SENDRAWTRANSACTION=
CHAIN_ID=0x128
MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com/
E2E_RELAY_HOST=
Run Code Online (Sandbox Code Playgroud)
请注意,OPERATOR_ID_MAIN和OPERATOR_KEY_MAIN已为门户获得,并已成功用于其他交易。
具体指令HEDERA_NETWORK是:
连接到哪个网络。自动填充主节点和镜像节点端点。可以是 MAINNET、PREVIEWNET、TESTNET 或网络 IP 映射 -> 节点 accountId,例如 {"127.0.0.1:50211":"0.0.3"}
但是,当我运行时npm run start,我收到以下错误Error: unknown network: TESTNET
...即使根据文档,这明确是允许的值。
(完整输出复制在下面<hr/>)。
启动 RPC 中继并将其连接到 Hedera 测试网的正确配置是什么?
> start
> npx lerna exec --scope @hashgraph/json-rpc-server -- npm run start
lerna notice cli v6.4.1
lerna info versioning independent
lerna notice filter including "@hashgraph/json-rpc-server"
lerna info …Run Code Online (Sandbox Code Playgroud) 我无法通过 HTTP 连接到 Hedera Testnet RPC 端点,\n确实,我间歇性地收到以下“未知错误”:\n\xe2\x80\x8b
\n[Request ID: fe7b9928-a23f-0d72-61a1-b7cd23658c01] Unknown error invoking RPC\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x80\x8b\n我正在使用以下 RPC 端点进行连接:\n\xe2\x80\x8b
\nhttps://testnet.hashio.io/api\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x80\x8b\n是否有替代(更可靠)的方法来连接到 Hedera 测试网?\n\xe2\x80\x8b
\n\xe2\x80\x8b\n我想使用 web3.js 或 ethers.js 与 Hedera 测试网进行交互。我该如何执行此操作?\n\xe2\x80\x8b\n我之前曾使用 与 Hedera Testnet 进行过交互hedera-sdk-js,\n例如使用以下代码:\n\xe2\x80\x8b
import {\n AccountBalanceQuery, \n Client\n} from "@hashgraph/sdk";\n\xe2\x80\x8b\nconst client = new Client({\n network: "testnet"\n});\n\xe2\x80\x8b\nconst accountId = \'0.0.3996280\';\nconst balance = await new AccountBalanceQuery()\n .setAccountId(accountId)\n .execute(client);\n \nconsole.log(\n `Balance of ${accountId} in Tinybars:`,\n balance.hbars.toTinybars().toString(10)\n);\n\xe2\x80\x8b\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x80\x8b\n如何在 web3.js/ ethers.js 中执行与上述相同的操作?
\n我知道这eth_estimateGas并不准确,\n但目前,我得到的实际gasUsed值\n大约是 \xc2\xa0 返回值的 6% eth_estimateGas。
在以下示例中,\n我使用完全相同的输入调用相同的智能合约两次,只有 1 个差异:
\ngasLimit = eth_estimateGasgasLimit = eth_estimateGas * 0.064\n // with exact estimated amount of gas\n const estimatedGas2 = (await expendGasSc.estimateGas.updateState(1_000_000_123n)).toBigInt();\n console.log(\'estimatedGas2\', estimatedGas2);\n const gasLimit2 = estimatedGas2 * 1n;\n console.log(\'gasLimit2\', gasLimit2);\n const txResponse2 = await (await expendGasSc\n .updateState(\n 1_000_000_123n,\n { gasLimit: gasLimit2 },\n ))\n .wait();\n const gasUsed2 = txResponse2.gasUsed.toBigInt();\n console.log(\'gasUsed2\', gasUsed2);\n\n // with …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 Hedera JS SDK 直接使用私钥作为输入来生成单个 ECDSA 密钥对,如下所示:
const privateKey = PrivateKey.fromStringECDSA(process.env.TARGET_HEX_PRIVATE_KEY);
Run Code Online (Sandbox Code Playgroud)
相反,我想做这样的事情,我使用 BIP-39 种子短语和派生路径作为输入:
const mnemonic = Mnemonic.fromString(process.env.TARGET_SEED_PHRASE);
const privateKey = await mnemonic.toEcdsaPrivateKey('', "m/44'/60'/0'/0/0");
Run Code Online (Sandbox Code Playgroud)
然而,根据其 JsDoc 注释,Mnemonic的toEcdsaPrivateKey函数似乎接受一个数字数组作为派生路径的输入@param,复制如下:
/**
* Recover an ECDSA private key from this mnemonic phrase, with an
* optional passphrase.
*
* @param {string} [passphrase]
* @param {number[]} [path]
* @returns {Promise<PrivateKey>}
*/
async toEcdsaPrivateKey(passphrase = "", path) {
return CACHE.privateKeyConstructor(
await this._mnemonic.toEcdsaPrivateKey(passphrase, path)
);
}
Run Code Online (Sandbox Code Playgroud)
在我的用例中,我想使用 MetaMask,不幸的是,它还不支持每个网络配置的自定义派生路径,而是硬编码了以太坊派生路径m/44'/60'/0'/0/0。请注意,前 …
我正在 Hashscan 上查看一笔交易
它的交易哈希是:
0x89eb7e219df6f8b3b3406c8a3698d5b484a4945059af643861c878e41ffc161b2589cc82ff40b4392ceb53856c5252c1
...这不适用于eth_getTransactionByHashRPC:
TXHASH=0x89eb7e219df6f8b3b3406c8a3698d5b484a4945059af643861c878e41ffc161b2589cc82ff40b4392ceb53856c5252c1
curl -s -X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":"2","method":"eth_getTransactionByHash","params":["'"${TXHASH}"'"]}' \
http://localhost:7546 | jq
Run Code Online (Sandbox Code Playgroud)
错误是:
{
"jsonrpc": "2.0",
"id": "2",
"error": {
"code": -32602,
"name": "Invalid parameter",
"message": "[Request ID: 5fda4d4a-3160-4f8f-8ed3-51ad64dada46] Invalid parameter 0: Expected 0x prefixed string representing the hash (32 bytes) of a transaction, value: 0x89eb7e219df6f8b3b3406c8a3698d5b484a4945059af643861c878e41ffc161b2589cc82ff40b4392ceb53856c5252c1"
}
Run Code Online (Sandbox Code Playgroud)
如何获得可在 RPC 中使用的交易哈希?