1

Sorry for noob question. I installed web3 (npm install web3),

but for some reason instead of calling web3 methods or showing object data, nodejs displays object structure:

> web3.eth.accounts
Accounts {
  currentProvider: [Getter/Setter],
  _requestManager:
   RequestManager {
     provider:
      HttpProvider {

when I connect to geth via geth attach, web3 embedded into geth works correctly

I am trying to use web3 from inside docker, Dockerfile is below:

FROM node:carbon

# Create app directory
WORKDIR /usr/src/app


# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN apt-get -y update && \
    apt-get -y install vim

RUN npm install

RUN npm install express

RUN npm install nodemon -g

RUN npm install hashmap && \
    npm install body-parser -g

# If you are building your code for production
# RUN npm install --only=production



# Bundle app source
COPY . .


CMD [ "nodemon", "start" ]
3
  • I can't tell without seeing your package.json, but I'm guessing you're using web3.js 1.0.0-beta in your docker instance, while geth uses web3.js 0.2x.x. web3.eth.getAccounts() probably does what you want.
    – user19510
    Feb 23, 2018 at 22:47
  • Web3.js methods return promises(in the new 1.0.0 beta), they are not the same as web3 api inside geth. Check the web3.js docs for examples
    – jeff
    Feb 23, 2018 at 22:48
  • yeah, package.json states that web3 is 1.0.0-beta.30: { "name": "ess_emulator", "version": "1.0.0", "description": "Node.js on Docker", "author": "Oleg Levchenko <[email protected]>", "main": "server.js", "scripts": { "start": "node server.js" }, "dependencies": { "body-parser": "^1.0.2", "express": "^4.16.2", "hashmap": "^2.3.0", "web3": "^1.0.0-beta.30" } }
    – Oleg
    Feb 23, 2018 at 23:15

2 Answers 2

0

The code below worked for me:

> web3.eth.getAccounts().then(console.log)

As per documentation: https://web3js.readthedocs.io/en/1.0/web3-eth.html#getaccounts

0

Try add await keyword on your code. Like:

await web3.eth.accounts

You are adding this, because: web3 returns a Promise. You can search what is promises in javascript.

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.