3

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.

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);
  • 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? – John Murphy Aug 10 '18 at 15:30
  • 1
    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 Aug 10 '18 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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