Comments (8)
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.
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.
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.
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.
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.
@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.
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.
@benjamincburns thank you for clearing the confusion.
from ganache-cli-archive.
Related Issues (20)
- ganache-cli not getting installed on Ubuntu HOT 2
- Error installing ganache-cli following Azure blockchain HelloWorld example HOT 3
- Unable to reach ganache-cli in a docker container from docker compose HOT 13
- eth_getTransactionCount returns an incorrect value HOT 2
- scrypt optional dependency HOT 1
- Ganache and BuilderEVM use different gas HOT 1
- How can I determine right ganache instance? HOT 2
- Extra bytes returned on revert("") HOT 2
- How to listen to existing Ganache instance in another Terminal tab or window? HOT 4
- How to retrieve transaction logs? HOT 4
- Ganache-cli Fork hang on net_version HOT 3
- Ganache-cli Fork will not last. Subsequent transactions fail with nonce error and / or out of gas error HOT 2
- Error: VM Exception while processing migration transaction: invalid opcode when testing on different machines HOT 3
- ganache-cli failing on estimateGas
- Error running -h "0.0.0.0" HOT 7
- How to use ganache-cli to fork the block specified by the bsc main network? HOT 2
- Ganache Crashes on estimateGas HOT 1
- can solidity have console.log()? HOT 2
- security vulnerabilities HOT 1
- [Errno 2] No such file or directory: 'ganache-cli'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ganache-cli-archive.