专用网络:web3.eth.getAccounts()始终发送空数组 [英] Private Network : web3.eth.getAccounts() always send empty array

查看:151
本文介绍了专用网络:web3.eth.getAccounts()始终发送空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个专用的以太坊网络.我确实使用 https://aws.amazon.com/blockchain/templates/

I am running a private Ethereum network. I do use https://aws.amazon.com/blockchain/templates/

整个设置已完成.事情看起来在AWS上正确设置了.现在,我正在尝试创建帐户并检索所有这些帐户.为此,我正在使用以下方法.

The entire setup has been done. Things look setup properly on AWS. Now, I am trying to create the account and retrieve all those accounts. For that, I am using methods as below.

Web3Service.js

Web3Service.js

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider(process.env.NETWORK_URL));

exports.getAccounts = function () {
    return web3.eth.getAccounts();
};

exports.createAccount = function () {
    return web3.eth.accounts.create();
};

app.js

var newAccount = await  web3Service.createAccount();
console.log('newAccount ', newAccount);

var accounts = await  web3Service.getAccounts();
console.log('accounts ', accounts);

我根本没有遇到任何错误.但是在 web3Service.getAccounts(); 的响应中,它总是空的 [] 数组.

I am not facing any errors at all. But in the response of the web3Service.getAccounts(); it's always empty [] array.

我已经验证了Etherium设置.所有节点均正常运行.

I have verified the Etherium setup. All nodes working perfectly.

您可以在此处找到整个代码库: blockchain-node示例整个代码库

You can find the entire codebase here : blockchain-node Sample entire codebase

推荐答案

苦苦挣扎后找到了解决方法:

After struggling found the solution :

Web3Service.js

Web3Service.js

/**
 *
 * Accounts Functions
 */

exports.createAccount = function () {
    /* *
     * Create Account Local Machine Only.
     * It will not return in web3.eth.getAccounts(); call
     */
    return web3.eth.accounts.create();
};

exports.createPersonalAccount = function (password) {
    /* *
     * Create Account in Node.
     * web3.eth.getAccounts();
     */
    return web3.eth.personal.newAccount(password);
};

app.js

var personalAccount = await web3Service.createPersonalAccount('123456789');
console.log('personalAccount ', personalAccount);

var accounts = await  web3Service.getAccounts();
console.log('accounts ', accounts);

更新源:工作源代码

没有明确地对密钥库做任何事情.

Thier is no explicitly do anything with keystore.

使用此-rpcapi db,eth,net,web3,personal 标志启动Geth.有必要.否则,您将面临错误.

Start your Geth using this --rpcapi db,eth,net,web3,personal flag. It is necessary. Otherwise, you will face the error.

这篇关于专用网络:web3.eth.getAccounts()始终发送空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆