Skip to content

Instantly share code, notes, and snippets.

@leon-do
Last active December 30, 2018 23:23
Show Gist options
  • Save leon-do/dfffeab8fa26e602941f937f7b9bca9e to your computer and use it in GitHub Desktop.
Save leon-do/dfffeab8fa26e602941f937f7b9bca9e to your computer and use it in GitHub Desktop.
const stellarSdk = require("stellar-sdk")
stellarSdk.Network.useTestNetwork()
const blockchain = new stellarSdk.Server("https://horizon-testnet.stellar.org")
// get private key from https://portal.willet.io/
const serverKeyPair = stellarSdk.Keypair.fromSecret("SB3KVB6RN5MOJJUZFLRDZNWN67PZV6IF6L74PMSHJEXHX2ABVSJUZDVA")
// get server account info
const serverAccount = await blockchain.loadAccount(serverKeyPair.publicKey())
// create a completely new and unique pair of keys
const escrowKeyPair = stellarSdk.Keypair.random()
// https://www.stellar.org/developers/js-stellar-base/reference/base-examples.html#creating-an-account
const transaction = new stellarSdk.TransactionBuilder(serverAccount)
.addOperation(
stellarSdk.Operation.createAccount({
destination: escrowKeyPair.publicKey(), // create escrow account
startingBalance: '2.00001' // 1 base + 0.5[base_reserve] per op(2) + tx fee (0.00001) => 2.00001 XLM minimum
})
)
.addOperation(
stellarSdk.Operation.setOptions({
source: escrowKeyPair.publicKey(),
signer: {
ed25519PublicKey: serverKeyPair.publicKey(), // add server as signer on escrow account
weight: 1
}
})
)
.build()
// sign transaction
transaction.sign(serverKeyPair, escrowKeyPair)
// broadcast transaction
await blockchain.submitTransaction(transaction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment