CryptoCurrency NODE js Web3 Ethereum - Can t connect to TESTRPC

0 votes

I am trying to connect to my testrpc instance from my web3 application but I can't seem to connect. The below code should return an array of all the accounts in the testrpc chain.

Code:
 

Web3 = require('web3') web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); console.log(web3.eth.accounts);

It returns the below and inside the object IntelliJ the current provider object is as follows. enter image description here

This shows that it only prints the object.

The testRPC server starts successfully too: enter image description here

Apr 6, 2022 in Blockchain by Rahul
• 9,670 points
445 views

1 answer to this question.

0 votes

Your connection is working. To return an array of the accounts use web3.eth.getAccounts() rather than web3.eth.accounts.

The code above should look something like this:-

Web3 = require('web3') 
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); web3.eth.getAccounts().then(accounts => console.log(accounts));

Which will give you something such as:-
 

[ '0x09e67e758381Fb878b9B1dCB91f2D5a62E00035a', '0x1BaABCa410a88564aC2BD9b8570D21b6e898C4C3', '0x8bfF74332C52065d2CC46f96c191aCDeec1AFEF2', '0x19070EaC7D68a710A5843Ee8cA3de258024da3Cb', '0x909394eA6feA0aDba05f093Ae43782e42b462F56', '0x63527Ef51b17830d6F597686C366A1995fd31bb2', '0xf476D31fAD8605d9D9D7b557C5117Bbe102935bc', '0xA64ba4e9d332106181A073E6eD20F876D6e28856', '0x126533F5FC78E355Fc35476Ae1392D338366D229', '0x291c17c0901FC9143D0DC43E1455E20D26342377' ]

answered Apr 12, 2022 by Soham
• 9,700 points

Related Questions In Blockchain

+1 vote
1 answer
0 votes
1 answer

Can't import "blockchain.info" to Node.js.. Need help.

Aurelia is a client-side framework and blockchain ...READ MORE

answered Jun 27, 2018 in Blockchain by Omkar
• 69,210 points
824 views
0 votes
1 answer

Docker: How to connect Node.js in container to Hyperledger Fabric?

You need to map ~/.composer/cards of your Docker host ...READ MORE

answered Oct 31, 2018 in Blockchain by Omkar
• 69,210 points
954 views
0 votes
1 answer

Not able to connect to Ethereum node in web browser

By default, geth listens only to localhost. ...READ MORE

answered Jan 16, 2019 in Blockchain by Omkar
• 69,210 points
1,705 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,696 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,235 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,145 views
0 votes
1 answer

How to swap an Ethereum ERC-20 and Neo NEP5 token with a smart contract?

Each blockchain is its own separated administration. ...READ MORE

answered Apr 12, 2022 in Blockchain by Soham
• 9,700 points
580 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP