if (window.freighterApi.isConnected()) {
alert("User has Freighter!");
}
const retrievePublicKey = async () => {
let publicKey = "";
let error = "";
try {
publicKey = await window.freighterApi.getPublicKey();
} catch (e) {
error = e;
}
if (error) {
return error;
}
return publicKey;
};
const result = retrievePublicKey();
Hi. This is Freighter Wallet javascript code. I try to find a way to get publicKey outside of this code. when I console.log(publicKey) after "await" everything ok. But I can't set publicKey to other variables to use outside of this code. When I set a variable after "await" and use it outside it is just undefined. result log gives me "promise pending". I can use "then" to get results on "console.log" . but still don't know any way to set the result to a variable to use.