如何配置 truffle 以连接到 RSK 测试网公共节点?

Posted

技术标签:

【中文标题】如何配置 truffle 以连接到 RSK 测试网公共节点?【英文标题】:How to configure truffle to connect to RSK Testnet public node? 【发布时间】:2021-06-19 22:22:16 【问题描述】:

我在松露中使用以下配置

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)

【问题讨论】:

【参考方案1】:

在您的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 中是不可配置的, 并设置为硬编码默认值。 这些是专门添加的,以便能够支持网络 具有不同的块间隔!

上下文:

adding provider.pollingInterval adding deploymentPollingInterval

【讨论】:

以上是关于如何配置 truffle 以连接到 RSK 测试网公共节点?的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 5 如何配置 Queue 数据库驱动程序以连接到非默认数据库?

BSC 测试网:Truffle 迁移 ETIMEDOUT

truffle部署到测试网rinkeby

有没有办法配置 Elastic Beanstalk 以连接到现有的 Oracle 数据库(没有 BYOL)?

Truffle 合约验证无法在 BSC 测试网上运行

如何设置连接 URL 以连接到 HSQLDB 中的多个数据库