10 请教一下truffle如何把合约部署到BSC测试网呢

我的truffle-config.js配置如下,但是报错了:

module.exports = {
  networks: {
    development: {
      host: "data-seed-prebsc-1-s1.binance.org", // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
    }
}
Something went wrong while attempting to connect to the network. Check your network configuration.
ProviderError: Invalid JSON RPC response: "<html>\r\n<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n<center>The plain HTTP request was sent to HTTPS port</center>\r\n</body>\r\n</html>\r\n"
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:73:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:102:1
    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/src/index.js:111:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
    at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Truffle v5.1.60 (core: 5.1.60)
Node v14.15.1
请先 登录 后评论

最佳答案 2021-05-18 14:18

应该是这样:

bsctest: {
provider: function() {
        return new HDWalletProvider(mnemonic, "https://data-seed-prebsc-1-s1.binance.org:8545/")
      },
      network_id: 97,
      gasPrice: 5000000000, 
    },

使用 HDWalletProvider 去链接provider.

请先 登录 后评论

其它 2 个回答

wangwei123
请先 登录 后评论
越泽 - 区块链爱好者
请先 登录 后评论