Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs unclear, error when creating an account #115

Closed
rizkysyazuli opened this issue Dec 23, 2017 · 15 comments · Fixed by stellar/js-stellar-base#161
Closed

Docs unclear, error when creating an account #115

rizkysyazuli opened this issue Dec 23, 2017 · 15 comments · Fixed by stellar/js-stellar-base#161

Comments

@rizkysyazuli
Copy link

rizkysyazuli commented Dec 23, 2017

I got an error from the very beginning. The code snippets in your "Create an Account" is very unclear.

Are they supposed to be inside a single or a separate files? (i pasted everything into one file)
Are they run from the browser or via Terminal? (i run it using Node from Terminal)

Anyway, here's the response that i get:

Unhandled rejection NotFoundError: [object Object]

SUCCESS! You have a new account :)
 { _links:
   { transaction:
      { href: 'https://horizon-testnet.stellar.org/transactions/4e3212bd9b1624fe501a0adc37126aafb785888fd45de3a52eb38cdbba1603d4' } },
  hash: '4e3212bd9b1624fe501a0adc37126aafb785888fd45de3a52eb38cdbba1603d4',
  ledger: 6182957,
  envelope_xdr: 'AAAAAGXNhLrhGtltTwCpmqlarh7s1DB2hIkbP//jgzn4Fos/AAAAZAAACT0AAMVDAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAD21ktzSjDM/q/1kSQANbZyD7gQDKEA0aSgM90zbk/uwAAAAXSHboAAAAAAAAAAAB+BaLPwAAAEBM2wZbgLDXe7NdKTGvHHiRGhnNsQ5F2d7TJK5scwTo69OMGWxR0K6K2kXnmWgRxLgMLaLLRRnxzIlxcT1907wO',
  result_xdr: 'AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA=',
  result_meta_xdr: 'AAAAAAAAAAEAAAADAAAAAABeWC0AAAAAAAAAAA9tZLc0owzP6v9ZEkADW2cg+4EAyhANGkoDPdM25P7sAAAAF0h26AAAXlgtAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAwBeWC0AAAAAAAAAAGXNhLrhGtltTwCpmqlarh7s1DB2hIkbP//jgzn4Fos/AAJ6s4+6ejQAAAk9AADFQwAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAQBeWC0AAAAAAAAAAGXNhLrhGtltTwCpmqlarh7s1DB2hIkbP//jgzn4Fos/AAJ6nEdDkjQAAAk9AADFQwAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAA' }
@rizkysyazuli rizkysyazuli changed the title Docs unclear, unable to create account Docs unclear, problem creating an account Dec 23, 2017
@rizkysyazuli rizkysyazuli changed the title Docs unclear, problem creating an account Docs unclear, error when creating an account Dec 23, 2017
@therealsanmah
Copy link

therealsanmah commented Jan 31, 2018

@rizkysyazuli - Agree, the docs in the page aren't super clear. You can put all of them into a single file like you have seem to done. There is one caveat though.

The second and third snippets are both asynchronous. The second snippet makes an API call to fund an account (and activate it), and only after that is successful, should you be executing the third snippet to get the account details.

In your case, since you've pasted all the snippets as they are, in order, your third snippet is executed even before the api call in the second snippet returns. So, it is not able to find the account details you're looking for and that fails with a NotFoundError. Since this is also a promise, and it doesn't have the catch block you see the error Unhandled rejection NotFoundError: [object Object].

This is the correct way to use the snippets from the documentation:

// create a completely new and unique pair of keys
// see more about KeyPair objects: https://stellar.github.io/js-stellar-sdk/Keypair.html
var StellarSdk = require('stellar-sdk')
var pair = StellarSdk.Keypair.random();
pair.secret();
// SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7
pair.publicKey();
// GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB

var request = require('request');
request.get({
  url: 'https://horizon-testnet.stellar.org/friendbot',
  qs: { addr: pair.publicKey() },
  json: true
}, function (error, response, body) {
  if (error || response.statusCode !== 200) {
    console.error('ERROR!', error || body);
  }
  else {
    console.log('SUCCESS! You have a new account :)\n', body);

    var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
    // the JS SDK uses promises for most actions, such as retrieving an account
    server.loadAccount(pair.publicKey()).then(function (account) {
      console.log('Balances for account: ' + pair.publicKey());
      account.balances.forEach(function (balance) {
        console.log('Type:', balance.asset_type, ', Balance:', balance.balance);
      });
    }).catch(function (err) {
      console.error(err);
    });
  }
});

@therealsanmah
Copy link

Also to answer the other part of your question on where do you run this. You can run this either in the terminal using node, like you've done or in the browser.

If you were to run in the browser though, just make sure you have a way to get the dependencies available in the browser (stellar-sdk and request npm modules).

@rizkysyazuli
Copy link
Author

got it! @therealsanmah. i'll try the tutorial again.

@michielmulders
Copy link

Is it possible to extend this code to make a transaction to another account?

@lhfly5201314
Copy link

Yeah,the docs are bad!I failed many times!
Thanks,@therealsanmah,you guy really did a great fixing job!

@lhfly5201314
Copy link

Wait a minute!I paste @therealsanmah's code in the nodejs console and run it,but it still failed!
The error is below:
data:
{ type: 'https://stellar.org/horizon-errors/not_found', title: 'Resource Missing', status: 404,
detail: 'The resource at the url requested was not found. This is usually occurs for one of two reasons: The url requested is not valid, or no data in our database could be found with the parameters provided.' } } }

The stellar official has change the API???Why does it failed to create accounts??

@maxpaynestory
Copy link

Docs are really confusing about creating an account

I tried friendbot hosted here https://horizon-testnet.stellar.org/friendbot

and it doesn't work.

I tried dockerize testnet hosted on my machine and it gives me error.

Friendbot is disabled

@bartekn
Copy link
Contributor

bartekn commented Mar 20, 2018

I fixed friendbot URL in stellar-deprecated/docs@bdb8ea7 (changes will be visible at stellar.org/developers in no more than 30 minutes from now).

@maxpaynestory
Copy link

Is that a friendbot for testnet?

@lhfly5201314
Copy link

Oh,I got it.The previous friendbot url is valid.We have to use the new url:https://friendbot.stellar.org
This will work.

@glowkeeper
Copy link

glowkeeper commented Mar 27, 2018

Agree - the docs don't make it clear that loadAccount needs to be done asynchronously.

Anyway, even after I called loadAccount via a callback fired via a successful friendbot account create Promise thingy, I was still getting intermittent failures. I seem to have fixed it by making the callback asynchronous, too. Something like this:

// This is the callback called from the successful request.get Promise
async getAccountCallback (_self, _address) {
    await _self.props.accountsHandler.getAccount(_address)
}

// where getAccount looks like this
getAccount (_address) {
    const address = _address
    var server = new StellarSdk.Server('localhost:8000'); // In reality, I set this up elsewhere...
     server.loadAccount(address).then(function(account) {
        console.log('Balances for account: ' + address);
        account.balances.forEach(function(balance) {
          console.log('Address:', address, 'Type:', balance.asset_type, ', Balance:', balance.balance)
        })
      })
  }
}

@MeKyleH
Copy link

MeKyleH commented Jul 15, 2018

Where can we go to suggest a PR to improve the docs? I'm working through them currently building out may app and I've run into a few snags that could be made clearer. Also, I've seen some typos that and code errors that could easily be fixed. Since I'm working through them it would be an ideal time for me to help add to them.

@robertDurst
Copy link
Contributor

Hey @MeKyleH, we always gladly accept doc improvement PR's and suggestions!

The repo for https://www.stellar.org/developers/guides/ is here: https://www.stellar.org/developers/guides/

The repo for https://www.stellar.org/developers/reference/ is here: https://github.com/stellar/go/tree/master/services/horizon/internal/docs/reference

Let me know if you have any issues finding things.

@MeKyleH
Copy link

MeKyleH commented Jul 16, 2018

@robertDurst I specifically found an issue with the code sample on this page: https://stellar.github.io/js-stellar-sdk/TransactionBuilder.html

Currently, it has:

var transaction = new TransactionBuilder(source)
 .addOperation(Operation.createAccount({
        destination: destinationA,
        startingBalance: "20"
    }) // <- funds and creates destinationA
    .addOperation(Operation.payment({
        destination: destinationB,
        amount: "100"
        asset: Asset.native()
    }) // <- sends 100 XLM to destinationB
  .build();

transaction.sign(sourceKeypair);

but it should be:

var transaction = new TransactionBuilder(source)
 .addOperation(Operation.createAccount({
        destination: destinationA,
        startingBalance: "20"
    })) // <- funds and creates destinationA
    .addOperation(Operation.payment({
        destination: destinationB,
        amount: "100",
        asset: Asset.native()
    })) // <- sends 100 XLM to destinationB
  
  .build();

transaction.sign(sourceKeypair);

Both of the inline comment lines need an additional closing paren and the amount line needs a comma added. I couldn't find where to go to fix this.

@robertDurst
Copy link
Contributor

We use jsdoc to generate the documentation, so the particular section you are interested in is a comment within the transaction builder file in js-stellar-sdk.

Here is what you are looking for: https://github.com/stellar/js-stellar-base/blob/master/src/transaction_builder.js#L18

morleyzhi added a commit to stellar-deprecated/docs that referenced this issue Feb 21, 2019
Rewrite the JS examples for creating an account with await so people can paste all the code into a console and run it without having to deal with async code.

Fixes stellar/js-stellar-sdk#115.
morleyzhi added a commit to stellar/js-stellar-base that referenced this issue Feb 21, 2019
- Add `Transaction.prototype.addSignature(publicKey: string, signature: string)` and `Transaction.prototype.getKeypairSIgnature(keypair: Keypair)` to allow, for example, parties to pre-sign their part of multi-signature transactions (fixes #109)
- Fix syntax errors in the TransactionBuilder example code (fixes stellar/js-stellar-sdk#115)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants