Last active
June 19, 2020 06:21
-
-
Save fukaoi/9dd8cb35cf157ab24fae13ed55fc5d47 to your computer and use it in GitHub Desktop.
To activate account when create stellar account on local pc
This file contains hidden or 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-testnet.stellar.org'); | |
const pubkey = 'GC5OTOME3BSLOSH46OZ64HMIOKLKFSS2PQ5ULFD4J6LLFS7IHZQT4O76'; | |
const secret = 'SBY37VIOJ7PN7LQBBPMTFTPIQXKHQW5X3RQQFMDXU2SUPQAYAHK5FJYU'; | |
const destination = ''; | |
(async () => { | |
const account = await server.loadAccount(pubkey); | |
const fee = await server.fetchBaseFee(); | |
const timeout = await server.fetchTimebounds(10); | |
try { | |
const transaction = new StellarSdk.TransactionBuilder(account, { | |
fee, | |
networkPassphrase: StellarSdk.Networks.TESTNET | |
}) | |
.addOperation(StellarSdk.Operation.createAccount({ | |
destination: destination, | |
startingBalance: '2.0', | |
})).setTimeout(timeout).build(); | |
transaction.sign(StellarSdk.Keypair.fromSecret(secret)); | |
await server.submitTransaction(transaction); | |
} catch (e) { | |
if (e.response == undefined) { | |
console.error(e) | |
} else { | |
console.error(e.response.data.extras.result_codes) | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment