我正在使用安全帽部署一个智能契约,它成功地部署到Polygon,但是当试图部署到RSK时,它失败了-
$ npx hardhat run scripts/deploy.js --network rsk
SocketError: closed
at Socket.onSocketClose (./node_modules/undici/lib/client.js:967:31)
at Socket.emit (events.js:400:28)
at TCP.<anonymous> (net.js:675:12) {
code: 'UND_ERR_SOCKET',
socket: {
localAddress: undefined,
localPort: undefined,
remoteAddress: undefined,
remotePort: undefined,
remoteFamily: undefined,
timeout: undefined,
bytesWritten: 209,
bytesRead: 125
}
}在hardhat.config.js中,RSK的定义如下-
...
networks: {
rsk: {
url: '...',
accounts: [...],
timeout: 120000,
},
polygon: {
url: '...',
accounts: [...],
},
},
...https://public-node.rsk.co节点上工作。那么,我的本地RSK节点会有什么问题呢?
发布于 2022-06-22 06:22:34
Hardhat v2.9.7使用undici v4,而后续版本使用undici v5。
要再现错误,请运行此命令,然后运行下面的测试脚本。
npm i --exact undici@4随后,运行此命令(切换到更新的undici版本),然后再次运行下面的测试脚本。
npm i --exact undici@5根本原因:undici v5期望HTTP响应包括content-length标题或transfer-encoding头。在上一个版本中,undici v4没有这个要求。
解决办法:将hardhat降级为早期版本: v2.9.7
解决方案:修正发送预期头的RSKj。
const { Client } = require('undici');
const rskRpcUrl =
process.env.RSK_RPC_URL ||
'https://public-node.testnet.rsk.co/'; // public node
// e.g. 'http://localhost:4444/' for local node
const client = new Client(rskRpcUrl);
client.request({
path: '/',
method: 'POST',
body: '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":67}',
headers: ["Content-Type", "application/json"],
}, function (err, data) {
if (err) {
console.log(err);
return
}
const {
statusCode,
headers,
trailers,
body
} = data
console.log('response received', statusCode)
console.log('headers', headers)
body.setEncoding('utf8')
body.on('data', console.log)
body.on('end', () => {
console.log('trailers', trailers)
})
client.close()
});发布于 2022-09-21 17:11:44
现在看来,这个问题在HOP-4.1.0中已经解决了。https://github.com/rsksmart/rskj/commit/554e549821c05b9977f4f1df1a53cb69e8f5e8b1
https://ethereum.stackexchange.com/questions/130028
复制相似问题