Created
January 11, 2020 20:20
-
-
Save ernestognw/e1dbf639e134780741ae42cba44aafdf to your computer and use it in GitHub Desktop.
Create and enable Stellar key pair for wallet
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
// utils/create-pair.js | |
const StellarSdk = require("stellar-sdk"); | |
const fs = require("fs"); | |
const path = require("path"); | |
const fetch = require("node-fetch"); | |
const pair = StellarSdk.Keypair.random(); | |
const createTestAccount = async () => { | |
// Creamos nuestro par de llaves | |
const secret = pair.secret(); | |
const publicKey = pair.publicKey(); | |
try { | |
// Solicitamos la activación de nuestra cuenta al friendbot de stellar | |
const response = await fetch( | |
`https://friendbot.stellar.org?addr=${publicKey}` | |
); | |
// Mostramos el resultado de la transacción | |
const responseJSON = await response.json(); | |
console.log(responseJSON); | |
// Escribimos un archivo secreto con nuestras llaves | |
fs.writeFileSync( | |
path.join(__dirname, "../", ".env"), | |
`SECRET=${secret}\nPUBLIC_KEY=${publicKey}` | |
); | |
console.log("SUCCESS! You have a new account :)"); | |
} catch (error) { | |
console.error("An error has occurred", error); | |
} | |
}; | |
createTestAccount(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment