Im building a bot that connects Stellar with Telegram but when I generate a new set of key pairs them don't match when I sign in stellarterm.

Here is the code:

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

// Stellar

function Wallet(){
  var pair = StellarSdk.Keypair.random();
  return{
    secret: pair.secret(),

    public: pair.publicKey()
  }
}

I'm trying to access like this:

Wallet().secret 
Wallet().public

But it returns me wrong set of pair keys. Any idea why it is happening and how can I fix it?

Each time your call the Wallet function it generates a new keypair. You should save the invocation result into a variable:

var keypair = Wallet()
console.log(keypair1.secret, keypair2.public)
var anotherKeypair = Wallet()
  • Thank you Orbit I see it returns now the correct set of keys but just one time. Do you know a way it can returns different key set each time I call the function? – Natoshi Sep 9 at 16:34
  • 3
    My friend, you should really start from learning the fundamentals. You won't be able to create anything adequate without basics. There are a lot of interactive JavaScript tutorials out there: codecademy, javascript.info. Also check modern es6 standard features and learn the basics of NodeJS. You will find answers for most of your questions there. – Orbit Lens Sep 9 at 19:44

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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