4

From the documentation you can make a request using Javascript to the "Friendbot" to receive test Lumens for an account:

// The SDK does not have tools for creating test accounts, so you'll have to
// make your own HTTP request.
var request = require('request');
request.get({
  url: 'https://friendbot.stellar.org',
  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);
  }
});

Is it possible to do something similar to this but that would send a request to an account where I have a large amount of XLM (my "reserve" account).

For context of this question: I would like to try to implement some method that upon creation of stellar wallets in my Dapp for users there would be a request sent so that some from my reserve of XLM would be sent to their account so they could cover base and minimum fees and pay to send tokens I would give them.

Thanks for any help, I'm just learning how to work with stellar.

1 Answer 1

2

There is an operation called createAccount, and it's used to activate accounts with a starting balance. In fact all friendbot does is exactly what you are saying (it has a base account with a large balance and it does createAccount with 10000 lumens).

https://stellar.github.io/js-stellar-sdk/Operation.html#.createAccount

Here's some sample code:

const transaction = new StellarSdk.TransactionBuilder(sourceAccount)
  .addOperation(StellarSdk.Operation.createAccount({
    destination: destinationId,
    startingBalance: "10"
   }))
   .build();

transaction.sign(sourceKeys);
return server.submitTransaction(transaction);
2
  • Thanks, so if I was to create accounts for an application I could use code like that to crate them and send a starting balance of XLM from the sourceAccount? How would I get a destinationId value though if the account was not yet created? Commented Aug 10, 2018 at 15:30
  • 2
    That's correct. You can generate a keypair (public/private key) without actually "creating it" on the stellar network by activating it with lumens. See stellar.github.io/js-stellar-sdk/Keypair.html#.random
    – Paul
    Commented Aug 10, 2018 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.