如何配置 truffle 以连接到 RSK 测试网 public 节点?
How to configure truffle to connect to RSK Testnet public node?
我在 truffle 中使用以下配置
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
},
rsk_testnet: {
host: "https://public-node.testnet.rsk.co",
network_id: '31',
gasPrice: 59240000, // 0.5924 Gwei
}
},
solc: {
optimizer: {
enabled: false
},
version: "0.5.17",
evmVersion: 'petersburg'
},
};
但是,我遇到了网络超时的间歇性错误。即
Invalid JSON RPC response: "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n</body>\r\n</html>\r\n"
at Object.InvalidResponse (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\web3\node_modules\web3-core-helpers\src\errors.js:42:1)
at t.InvalidResponse [as onreadystatechange] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\web3\node_modules\web3-providers-http\src\index.js:92:1)
at t._a [as dispatchEvent] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request-event-target.js:27:61)
at t.dispatchEvent [as _setReadyState] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request.js:208:1)
at t._setReadyState [as _onHttpResponseEnd] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request.js:318:1)
at IncomingMessage._onHttpResponseEnd (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request.js:289:47)
at IncomingMessage.emit (events.js:198:15)
at endReadableNT (_stream_readable.js:1139:12)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
在您的 truffle-config.js
文件中:
(1) 设置变量testnetSeedPhrase
为
包含有效的 BIP-39 助记词
(2) 设置变量gasPriceTestnet
为
包含您希望使用的以 Wei 计价的 gas 价格。
(3) 在导出的 config
对象中,
将 config.networks.testnet
的值设置为以下内容。
...
testnet: {
provider: () => new HDWalletProvider({
mnemonic: {
phrase: testnetSeedPhrase,
},
providerOrUrl: 'https://public-node.testnet.rsk.co/',
// Higher polling interval to check for blocks less frequently
pollingInterval: 15e3,
}),
// Ref: http://developers.rsk.co/rsk/architecture/account-based/#chainid
network_id: 31,
gasPrice: gasPriceTestnet,
networkCheckTimeout: 1e6,
timeoutBlocks: 100,
// Higher polling interval to check for blocks less frequently
// during deployment
deploymentPollingInterval: 15e3,
},
...
(4) 现在您可以 运行 truffle
选择此网络的子命令,
例如:
truffle migrate --network testnet
请注意,这些选项最初在 Truffle 中是不可配置的,
并设置为硬编码默认值。
这些是专门添加的,以便能够支持网络
具有不同的块间隔!
上下文:
我在 truffle 中使用以下配置
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
},
rsk_testnet: {
host: "https://public-node.testnet.rsk.co",
network_id: '31',
gasPrice: 59240000, // 0.5924 Gwei
}
},
solc: {
optimizer: {
enabled: false
},
version: "0.5.17",
evmVersion: 'petersburg'
},
};
但是,我遇到了网络超时的间歇性错误。即
Invalid JSON RPC response: "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n</body>\r\n</html>\r\n"
at Object.InvalidResponse (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\web3\node_modules\web3-core-helpers\src\errors.js:42:1)
at t.InvalidResponse [as onreadystatechange] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\web3\node_modules\web3-providers-http\src\index.js:92:1)
at t._a [as dispatchEvent] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request-event-target.js:27:61)
at t.dispatchEvent [as _setReadyState] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request.js:208:1)
at t._setReadyState [as _onHttpResponseEnd] (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request.js:318:1)
at IncomingMessage._onHttpResponseEnd (node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\xhr2-cookies\dist\xml-http-request.js:289:47)
at IncomingMessage.emit (events.js:198:15)
at endReadableNT (_stream_readable.js:1139:12)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
在您的 truffle-config.js
文件中:
(1) 设置变量testnetSeedPhrase
为
包含有效的 BIP-39 助记词
(2) 设置变量gasPriceTestnet
为
包含您希望使用的以 Wei 计价的 gas 价格。
(3) 在导出的 config
对象中,
将 config.networks.testnet
的值设置为以下内容。
...
testnet: {
provider: () => new HDWalletProvider({
mnemonic: {
phrase: testnetSeedPhrase,
},
providerOrUrl: 'https://public-node.testnet.rsk.co/',
// Higher polling interval to check for blocks less frequently
pollingInterval: 15e3,
}),
// Ref: http://developers.rsk.co/rsk/architecture/account-based/#chainid
network_id: 31,
gasPrice: gasPriceTestnet,
networkCheckTimeout: 1e6,
timeoutBlocks: 100,
// Higher polling interval to check for blocks less frequently
// during deployment
deploymentPollingInterval: 15e3,
},
...
(4) 现在您可以 运行 truffle
选择此网络的子命令,
例如:
truffle migrate --network testnet
请注意,这些选项最初在 Truffle 中是不可配置的, 并设置为硬编码默认值。 这些是专门添加的,以便能够支持网络 具有不同的块间隔!
上下文: