Last active
December 30, 2018 23:23
-
-
Save leon-do/dfffeab8fa26e602941f937f7b9bca9e to your computer and use it in GitHub Desktop.
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") | |
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