Skip to content

Instantly share code, notes, and snippets.

@dolcalmi
Created July 7, 2019 18:49
Show Gist options
  • Save dolcalmi/3d8d9ebb9b049322cbacb538cebf250a to your computer and use it in GitHub Desktop.
Save dolcalmi/3d8d9ebb9b049322cbacb538cebf250a to your computer and use it in GitHub Desktop.
Stellar account creation
const StellarSdk = require('stellar-sdk');
const server = new StellarSdk.Server('https://horizon.stellar.org')
const source = StellarSdk.Keypair.fromSecret('SC...CU');
const destination = StellarSdk.Keypair.fromPublicKey('GAD...PZR')
StellarSdk.Network.usePublicNetwork();;
server.accounts()
.accountId(source.publicKey())
.call()
.then(({ sequence }) => {
const account = new StellarSdk.Account(source.publicKey(), sequence)
const transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE
})
.addOperation(StellarSdk.Operation.createAccount({
destination: destination.publicKey(),
startingBalance: '1'
}))
.setTimeout(StellarSdk.TimeoutInfinite)
.build()
transaction.sign(source)
return server.submitTransaction(transaction)
})
.then(results => {
console.log('Transaction', results._links.transaction.href)
})
.catch(err => {
console.log('error', err);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment