Undefined results for “web3.eth.accounts” in truffle console












1















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










share|improve this question







New contributor




Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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
















1















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










share|improve this question







New contributor




Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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














1












1








1








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










share|improve this question







New contributor




Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question







New contributor




Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Yash ShuklaYash Shukla

183




183




New contributor




Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Yash Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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














  • 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








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










2 Answers
2






active

oldest

votes


















2














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];





share|improve this answer































    2














    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];
    })





    share|improve this answer























      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.










      draft saved

      draft discarded


















      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









      2














      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];





      share|improve this answer




























        2














        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];





        share|improve this answer


























          2












          2








          2







          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];





          share|improve this answer













          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];






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          Kaki Master Of TimeKaki Master Of Time

          1,203218




          1,203218























              2














              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];
              })





              share|improve this answer




























                2














                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];
                })





                share|improve this answer


























                  2












                  2








                  2







                  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];
                  })





                  share|improve this answer













                  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];
                  })






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Alex WAlex W

                  291




                  291






















                      Yash Shukla is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      RAC Tourist Trophy