01-edu / Branch-Blockchain

⛓️ Repository for the Blockchain branch content.
3 stars 5 forks source link

localhost and 127.0.0.1 in quest 4 exercise 2 #19

Open Hamzaelkhatri opened 2 years ago

Hamzaelkhatri commented 2 years ago

When I run the solution and test without inserting any param in JsonRpcProvider -> localhost:8545 , I got this message :

Error: missing response (...)
 ...
{
  reason: 'missing response',
  code: 'SERVER_ERROR',
  requestBody: '{"method":"eth_accounts","params":[],"id":42,"jsonrpc":"2.0"}',
  requestMethod: 'POST',
  serverError: Error: connect ECONNREFUSED ::1:8545
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1237:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '::1',
    port: 8545
  },
  url: 'http://localhost:8545'
}

but I added 127.0.0.1 in the JsonRpcProvider params, and everything works as expected

async function getAccount() {
    const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545");
    const accounts = await provider.listAccounts();
    console.log(accounts[0])
    return accounts[0]
}