Undefined results for “web3.eth.accounts” in truffle console
truffle(development)> web3.eth.accounts[0]
gives output as "undefined"
truffle(development)> web3.eth.accounts
instead of showing all accounts details gives the below output
Accounts {
currentProvider: [Getter/Setter],
_requestManager:
RequestManager {
provider:
HttpProvider {
host: 'http://127.0.0.1:7545',
httpAgent: [Agent],
timeout: 0,
headers: undefined,
connected: true,
send: [Function],
......blah...blah
but...
truffle(development)> web3.eth.getAccounts
is working. please help
web3js truffle
New contributor
add a comment |
truffle(development)> web3.eth.accounts[0]
gives output as "undefined"
truffle(development)> web3.eth.accounts
instead of showing all accounts details gives the below output
Accounts {
currentProvider: [Getter/Setter],
_requestManager:
RequestManager {
provider:
HttpProvider {
host: 'http://127.0.0.1:7545',
httpAgent: [Agent],
timeout: 0,
headers: undefined,
connected: true,
send: [Function],
......blah...blah
but...
truffle(development)> web3.eth.getAccounts
is working. please help
web3js truffle
New contributor
1
Ifweb3.eth.getAccounts
is working, then why don't you simply use it??? As of web3.js v1,web3.eth.accounts
is deprecated.
– goodvibration
yesterday
I can use it but I am not able to choose any of the accounts specifically which I was able to do with 'web3.eth.accounts[0]" , please let me know the replacement for this?
– Yash Shukla
yesterday
1. You cannot use it, as it isundefined
; you even specify it in your own question! 2. You've already found a replacement, and again - you even specify it in your own question!
– goodvibration
yesterday
add a comment |
truffle(development)> web3.eth.accounts[0]
gives output as "undefined"
truffle(development)> web3.eth.accounts
instead of showing all accounts details gives the below output
Accounts {
currentProvider: [Getter/Setter],
_requestManager:
RequestManager {
provider:
HttpProvider {
host: 'http://127.0.0.1:7545',
httpAgent: [Agent],
timeout: 0,
headers: undefined,
connected: true,
send: [Function],
......blah...blah
but...
truffle(development)> web3.eth.getAccounts
is working. please help
web3js truffle
New contributor
truffle(development)> web3.eth.accounts[0]
gives output as "undefined"
truffle(development)> web3.eth.accounts
instead of showing all accounts details gives the below output
Accounts {
currentProvider: [Getter/Setter],
_requestManager:
RequestManager {
provider:
HttpProvider {
host: 'http://127.0.0.1:7545',
httpAgent: [Agent],
timeout: 0,
headers: undefined,
connected: true,
send: [Function],
......blah...blah
but...
truffle(development)> web3.eth.getAccounts
is working. please help
web3js truffle
web3js truffle
New contributor
New contributor
New contributor
asked yesterday
Yash ShuklaYash Shukla
183
183
New contributor
New contributor
1
Ifweb3.eth.getAccounts
is working, then why don't you simply use it??? As of web3.js v1,web3.eth.accounts
is deprecated.
– goodvibration
yesterday
I can use it but I am not able to choose any of the accounts specifically which I was able to do with 'web3.eth.accounts[0]" , please let me know the replacement for this?
– Yash Shukla
yesterday
1. You cannot use it, as it isundefined
; you even specify it in your own question! 2. You've already found a replacement, and again - you even specify it in your own question!
– goodvibration
yesterday
add a comment |
1
Ifweb3.eth.getAccounts
is working, then why don't you simply use it??? As of web3.js v1,web3.eth.accounts
is deprecated.
– goodvibration
yesterday
I can use it but I am not able to choose any of the accounts specifically which I was able to do with 'web3.eth.accounts[0]" , please let me know the replacement for this?
– Yash Shukla
yesterday
1. You cannot use it, as it isundefined
; you even specify it in your own question! 2. You've already found a replacement, and again - you even specify it in your own question!
– goodvibration
yesterday
1
1
If
web3.eth.getAccounts
is working, then why don't you simply use it??? As of web3.js v1, web3.eth.accounts
is deprecated.– goodvibration
yesterday
If
web3.eth.getAccounts
is working, then why don't you simply use it??? As of web3.js v1, web3.eth.accounts
is deprecated.– goodvibration
yesterday
I can use it but I am not able to choose any of the accounts specifically which I was able to do with 'web3.eth.accounts[0]" , please let me know the replacement for this?
– Yash Shukla
yesterday
I can use it but I am not able to choose any of the accounts specifically which I was able to do with 'web3.eth.accounts[0]" , please let me know the replacement for this?
– Yash Shukla
yesterday
1. You cannot use it, as it is
undefined
; you even specify it in your own question! 2. You've already found a replacement, and again - you even specify it in your own question!– goodvibration
yesterday
1. You cannot use it, as it is
undefined
; you even specify it in your own question! 2. You've already found a replacement, and again - you even specify it in your own question!– goodvibration
yesterday
add a comment |
2 Answers
2
active
oldest
votes
from @goodvibration in the comments :
web3.eth.accounts is deprecated.
That is true. in the newer version of web3.js
web3.eth.getAccounts
returns a promise, so that is why doing :
var accounts = web3.eth.getAccounts();
accounts[0];
will return undefined
.
TLDR : use this code instead (if it works, didn't test) :
var accounts = await web3.eth.getAccounts();
accounts[0];
add a comment |
Use the code below to retrieve all the accounts
var accounts = web3.eth.getAccounts();
Use this code to reference a single account
var account0;
web3.eth.getAccounts().then(function(result){
account0 = result[0];
})
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "642"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Yash Shukla is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f66202%2fundefined-results-for-web3-eth-accounts-in-truffle-console%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
from @goodvibration in the comments :
web3.eth.accounts is deprecated.
That is true. in the newer version of web3.js
web3.eth.getAccounts
returns a promise, so that is why doing :
var accounts = web3.eth.getAccounts();
accounts[0];
will return undefined
.
TLDR : use this code instead (if it works, didn't test) :
var accounts = await web3.eth.getAccounts();
accounts[0];
add a comment |
from @goodvibration in the comments :
web3.eth.accounts is deprecated.
That is true. in the newer version of web3.js
web3.eth.getAccounts
returns a promise, so that is why doing :
var accounts = web3.eth.getAccounts();
accounts[0];
will return undefined
.
TLDR : use this code instead (if it works, didn't test) :
var accounts = await web3.eth.getAccounts();
accounts[0];
add a comment |
from @goodvibration in the comments :
web3.eth.accounts is deprecated.
That is true. in the newer version of web3.js
web3.eth.getAccounts
returns a promise, so that is why doing :
var accounts = web3.eth.getAccounts();
accounts[0];
will return undefined
.
TLDR : use this code instead (if it works, didn't test) :
var accounts = await web3.eth.getAccounts();
accounts[0];
from @goodvibration in the comments :
web3.eth.accounts is deprecated.
That is true. in the newer version of web3.js
web3.eth.getAccounts
returns a promise, so that is why doing :
var accounts = web3.eth.getAccounts();
accounts[0];
will return undefined
.
TLDR : use this code instead (if it works, didn't test) :
var accounts = await web3.eth.getAccounts();
accounts[0];
answered yesterday
Kaki Master Of TimeKaki Master Of Time
1,203218
1,203218
add a comment |
add a comment |
Use the code below to retrieve all the accounts
var accounts = web3.eth.getAccounts();
Use this code to reference a single account
var account0;
web3.eth.getAccounts().then(function(result){
account0 = result[0];
})
add a comment |
Use the code below to retrieve all the accounts
var accounts = web3.eth.getAccounts();
Use this code to reference a single account
var account0;
web3.eth.getAccounts().then(function(result){
account0 = result[0];
})
add a comment |
Use the code below to retrieve all the accounts
var accounts = web3.eth.getAccounts();
Use this code to reference a single account
var account0;
web3.eth.getAccounts().then(function(result){
account0 = result[0];
})
Use the code below to retrieve all the accounts
var accounts = web3.eth.getAccounts();
Use this code to reference a single account
var account0;
web3.eth.getAccounts().then(function(result){
account0 = result[0];
})
answered yesterday
Alex WAlex W
291
291
add a comment |
add a comment |
Yash Shukla is a new contributor. Be nice, and check out our Code of Conduct.
Yash Shukla is a new contributor. Be nice, and check out our Code of Conduct.
Yash Shukla is a new contributor. Be nice, and check out our Code of Conduct.
Yash Shukla is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ethereum Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f66202%2fundefined-results-for-web3-eth-accounts-in-truffle-console%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If
web3.eth.getAccounts
is working, then why don't you simply use it??? As of web3.js v1,web3.eth.accounts
is deprecated.– goodvibration
yesterday
I can use it but I am not able to choose any of the accounts specifically which I was able to do with 'web3.eth.accounts[0]" , please let me know the replacement for this?
– Yash Shukla
yesterday
1. You cannot use it, as it is
undefined
; you even specify it in your own question! 2. You've already found a replacement, and again - you even specify it in your own question!– goodvibration
yesterday