I'm creating my monero wallets using the monero-javascript
javascript library and this is the code I use
async function createWalletFull(password, mnemonic, id, network) {
try {
let wallet
if (network == "TESTNET") {
wallet = await monerojs.createWalletFull({
networkType: MoneroNetworkType.TESTNET,
password: password,
mnemonic: mnemonic,
serverUri: "http://127.0.0.1:28081",
path: <path>
});
} else {
wallet = await monerojs.createWalletFull({
networkType: MoneroNetworkType.MAINNET,
password: password,
mnemonic: mnemonic,
serverUri: "http://127.0.0.1:28081",
path: <path>
});
}
return wallet
} catch (error) {
throw new Error("Error during creation of the wallet: " + error.message);
}
}
async function createAddressMonero(coin, path, child, network, id_utente,index=0) {
const privateKey = child.privateKey.toString("hex");
let wallet;
const mnemonic = mnemonicGen.mn_encode(
privateKey,
"english"
);
if (network == "TESTNET") {
wallet = await createWalletFull("password", mnemonic, id_utente, "TESTNET")
} else {
wallet = await createWalletFull("password", mnemonic, id_utente, "MAINNET")
}
console.log("\n---------Monero---------\n");
let primaryAddress = await wallet.getPrimaryAddress();
let publicSpendKey = await wallet.getPublicSpendKey();
let publicViewKey = await wallet.getPublicViewKey();
let privateSpendKey = await wallet.getPrivateSpendKey();
let privateViewKey = await wallet.getPrivateViewKey();
await saveOnDB() //function to save on DB the wallet
}
async function generation(Masternode, network) {
Object.keys(COIN_TYPE).forEach(async (coin) => {
const path = `m/44'/${COIN_TYPE[coin]}'/${ACCOUNT_INDEX}'/${CHANGE_INDEX}/0`;
const child = Masternode.derivePath(path);
const privateKey = child.privateKey.toString("hex");
const publicKey = child.publicKey.toString("hex");
console.log("child Private key:", privateKey);
console.log("child Public key:", publicKey);
// other code esecuted...
//address creation for MONERO Blockchain
if (coin === "XMR") {
await createAddressMonero(coin, path, child, network);
}
}); }
it's as if await didn't work with the createWalletFull
function, as the Monero worker intervenes and immediately returns nullifying await. Is there any solution to make createWalletFull asynchronous?
While executing the program, the end of the execution of this function is not waited.
await
in this context is the wallet being created, not that it has synchronized with the network or something else. Hence, what are you expectingawait
to be waiting on?