1

On the page https://www.stellar.org/developers/guides/get-started/create-account.html is stated:

"You can generate the seed and key with the following command"

// create a completely new and unique pair of keys
// see more about KeyPair objects: https://stellar.github.io/js-stellar-sdk/Keypair.html
var pair = StellarSdk.Keypair.random();

pair.secret();
// SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7
pair.publicKey();
// GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB

I figured I would have to enter the commands in the commandprompt after starting my docker container. The commands are formatted as though it's supposed to be stored in some file format and called afterwards.

Either way, I seem to enter these commands in the wrong place because I get no response.

Where and how am I to execute the commands?

4

To use this commands you have to import the SDK in your javascript or java application and define the horizon-server you wanna use

for javascript (nodejs) its like:

var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

for pure clientside javascript its like

<script src="./stellarsdk/stellar-sdk.js"></script>
<script>
    console.log(StellarSdk);

    var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

</script>

then you can use in your script

var pair = StellarSdk.Keypair.random();

pair.secret();
pair.publicKey();
  • thank you. Together with the post below, this solved my issue. – Sybren Feb 9 '18 at 12:09
1

Since you are trying to do this from the command line, if you are on a Mac or Linux first install Nodejs by downloading the binaries from the nodejs org site, (should not be too dissimilar on windows). Create a project folder where you'll run commands and install Nodejs modules.

Go to your project folder from the terminal and type:

npm install --save stellar-sdk

This will install your dependencies in a new folder named node_modules. Note that npm stands for Node Package Manager and it will be installed when you install Nodejs. The --save option is to instruct Nodejs to write the dependency name in the package.json file. Don't worry about it if you're not a developer.

Now create a file with .js extension and save it in your project folder after copying/pasting this code:

const StellarSdk = require('stellar-sdk');


var pair = StellarSdk.Keypair.random();

var keys = {};

keys.secret = pair.secret();
keys.public = pair.publicKey();


console.log(keys);

Assuming you named this file myStellarKeyPairGenerator.js you can run the code above by typing in the console:

node myStellarKeyPairGenerator.js

This will print your key pair on the terminal console. The chances someone could have generated the same key pair are considered so unlikely in your lifetime you don't actually need to validate and create a real account on the Stellar network itself. If you want this account to actually exist on the Stellar network you must send Lumens to the public address you've generated.

Make sure to save those keys and optionally encrypt the secret key (not a hash from which you can't derive you key) with a password you'll remember especially if you print them out on paper for cold storage.

  • I had to try this several times. npm didn't seem to be able to install the packages correctly. I tried several times. I think what did the trick was that I did a npm init before the npm install commands. – Sybren Feb 9 '18 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.