Git Product home page Git Product logo

Comments (8)

tcoulter avatar tcoulter commented on July 17, 2024

You're not passing the same options to TestRPC.provider() as you are to the
command line. Check out the readme.
On Apr 3, 2016 11:32 AM, "Jean-Marc Le Roux" [email protected]
wrote:

Here is my code:

var web3 = new Web3();web3.setProvider(TestRPC.provider());
web3.eth.getAccounts((err, acc) => {
console.log(acc);
});

Here is what I get:

[ '0x871f46e97b6419ce887073a9ccb99b964d438bdd',
'0x728ef897367608fd7ce8b9dbc66eb840d9cbc63c',
'0x4f7aef45c0a6c311e15a16a766ac95673978886f',
'0x92dce6468f51c35266c70b176c6771ac648eb305',
'0xaf4381f1861c78d399dcdc3c0f36d6fff22086af',
'0x11d9e50c259ffe93e9fd6f95967599387c4c1ee1',
'0x55ef102990a7c9fe26d9756da1de372e91e3aaf8',
'0xe06e79a7c975d1d94ad32ada38855ca701d9dd8a',
'0x99a17f3c5e4ce7a684d1aa4a805b720ccde276b9',
'0x513fd961555c0687c81a8465a9ea0a855a408457' ]

Here is what I have in the testrpc logs:

EthereumJS TestRPC v2.0.0

Available Accounts

(0) 0x4e4134b36b3e7f8fca80a2fbfe6d54549e5f0f93

Private Keys

(0) 81aa38abb2b5d5aa3bbc0c852423cca1118dc90ef1a83c18fc8010fb276ec378

But if I use the classic HTTP Provider, the account list is correct:

var web3 = new Web3();web3.setProvider(new web3.providers.HttpProvider("http://127.0.0.1:8545"));
web3.eth.getAccounts((err, acc) => {
console.log(acc);
});

[ '0x4e4134b36b3e7f8fca80a2fbfe6d54549e5f0f93' ]

Any idea what's wrong?

Thanks,


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#54

from ganache-cli-archive.

JMLX42 avatar JMLX42 commented on July 17, 2024

I don't understand. You mean that I shoud either use the TestRPC.provider OR run the testrpc binary, but not both ?
I thought TestRPC.provider was a specific provider to connect to the testrpc binary server.

from ganache-cli-archive.

tcoulter avatar tcoulter commented on July 17, 2024

Yes. When you use TestRPC.provider(), you're using the TestRPC as a library
and creating a whole new instance of the TestRPC in memory.

So the correct usage is to use the HttpProvider + the TestRPC server
together, or only use the TestRPC as a provider on its own.
On Apr 3, 2016 11:36 AM, "Jean-Marc Le Roux" [email protected]
wrote:

I don't understand. You mean that I shoud either use the TestRPC.provider
OR run the testrpc binary, but not both ?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#54 (comment)

from ganache-cli-archive.

danielyaa5 avatar danielyaa5 commented on July 17, 2024

Im also having trouble understanding. I don't understand the difference between new web3.providers.HttpProvider("http://127.0.0.1:8545") and passing TestRPC.provider()

from ganache-cli-archive.

10247bit avatar 10247bit commented on July 17, 2024

I think i am facing similar problem, I have used a infura address instead of localhost"const web3 = new Web3(new Web3.providers.HttpProvider("https://kovan.infura.io/TOKEN_ID")); and when i am executing the web3.eth.getAccounts((err, acc) => { console.log(acc); }); it is returning an empty array, but my metamask window have 2 accounts

from ganache-cli-archive.

benjamincburns avatar benjamincburns commented on July 17, 2024

@IntenseRave to understand what's going on there, see the JSONRPC wiki page for eth_accounts.

When you run web3.eth.getAccounts with an HTTP provider pointed at infura, you're sending the eth_accounts RPC request over to Infura. Infura is then responding with the (empty) list of accounts it owns. "Owns" in this context means "holds the private key." Since Infura is a public client, it doesn't hold anybody's private keys, meaning it can't sign any transactions for you.

Instead, your choices are to write your Dapp so that it holds the private key, signs transactions, and sends them via eth_sendRawTransaction (don't do this), or to rely on wallet providers like MetaMask to hold your keys and sign transactions for you/your users (do this). For more info on that, see this FAQ.

from ganache-cli-archive.

benjamincburns avatar benjamincburns commented on July 17, 2024

Also just a tip for the future - you're far more likely to get a quick/informative response to questions like this on our gitter channel than you are here. There are ≥3000 people there to answer things. Here there's just me, and sometimes I can take over a week to respond.

from ganache-cli-archive.

10247bit avatar 10247bit commented on July 17, 2024

@benjamincburns thank you for clearing the confusion.

from ganache-cli-archive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.