1

I'm using Hardhat to deploy a smart contract, it's deployed successfully to Polygon, but when trying to deploy into RSK, it fails with -

$ 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
  }
}

In hardhat.config.js, RSK is defined as following -

    ...
    networks: {
        rsk: {
            url: '...',
            accounts: [...],
            timeout: 120000,
        },
        polygon: {
            url: '...',
            accounts: [...],
        },
    },
    ...
  1. It happens on two different synced local RSKJ nodes, same result - but works on the public https://public-node.rsk.co node.
  2. It worked in the past on my local nodes, nothing changed since! (that I know of)

So what could be the issue with my local RSK nodes?

2
  • can you share the full networks.rsk object in the hardhat config file pls? (redact any seed phrases or private keys, of course)
    – bguiz
    Jun 15, 2022 at 12:40
  • if you're using a custom config for your local RSKj node, can you also pls share the RSK config file? plus the command that you're using to start the RSKj node.
    – bguiz
    Jun 15, 2022 at 12:41

2 Answers 2

0

Hardhat v2.9.7 uses undici v4, whereas subsequent versions use undici v5.

To reproduce the error, run this command, then run the test script below.

npm i --exact undici@4

Subsequently, run this command (to switch to newer undici version), then run the test script below again.

npm i --exact undici@5

Underlying cause: undici v5 expects a HTTP response to include either a content-length heading or a transfer-encoding header. The previous version, undici v4 does not have this requirement.

Workaround: Downgrade to earlier version of hardhat: v2.9.7

Solution: Fix in RSKj that sends the expected headers.


Test Script

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()
});
0

Looks like this is fixed in HOP-4.1.0, now. https://github.com/rsksmart/rskj/commit/554e549821c05b9977f4f1df1a53cb69e8f5e8b1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.