Reputation: 49
I was wondering how can I access this two objects "public" and "secret" in the Wallet function here:
function Wallet(){
var pair = StellarSdk.Keypair.random();
return{
public: pair.publicKey(),
secret: pair.secret()
}
}
Are they objects? I mean, is this function returning an array?
I'm trying this:
Wallet().public
Wallet().secret
But it returns me a different set of keys, they don't match cause I am calling twice the function, so I figured it out it corresponds a different key each time I call it.
How can I access these two "public" and "secret" strings but just calling at once the function?
Upvotes: 1
Views: 56
Reputation: 3040
function Wallet(){
var pair = StellarSdk.Keypair.random();
var obj={
public: pair.publicKey(),
secret: pair.secret()
}
return obj;
}
var wallet = Wallet();
console.log(wallet.puplic);
console.log(wallet.secret);
Upvotes: 0
Reputation: 10096
You first have to save the return value of Wallet
to a variable and then access the public and private key:
let wallet = Wallet();
wallet.public;
wallet.private;
This way Wallet
, and therefore StellarSdk.Keypair.random();
is only executed once.
Upvotes: 1