很抱歉问你这个问题。我安装了web3 (npm安装web3),
但出于某种原因,nodejs显示对象结构,而不是调用web3方法或显示对象数据:
> web3.eth.accounts
Accounts {
currentProvider: [Getter/Setter],
_requestManager:
RequestManager {
provider:
HttpProvider {当我通过geth附加连接到geth时,嵌入到geth中的web3工作正常。
我试图从内部码头使用web3,Dockerfile如下所示:
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" ]发布于 2018-02-23 23:56:23
下面的代码适用于我:
> web3.eth.getAccounts().then(console.log)根据文档:https://web3js.readthedocs.io/en/1.0/web3-eth.html#getaccounts
发布于 2021-09-12 20:14:26
尝试在代码中添加await关键字。比如:
await web3.eth.accounts您要添加此内容,因为: web3返回一个承诺。您可以在javascript中搜索什么是承诺。
https://ethereum.stackexchange.com/questions/40733
复制相似问题