Created
July 7, 2019 18:49
-
-
Save dolcalmi/3d8d9ebb9b049322cbacb538cebf250a to your computer and use it in GitHub Desktop.
Stellar account creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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