0

I've successfully created all the account "bits" from mnemonic (generated here for tests):

const monerojs = require("monero-javascript");

const mnemonic = ...
const moneroNetwork = monerojs.MoneroNetworkType.TESTNET;
// in async func
    const wallet = await monerojs.createWalletKeys({
        networkType: moneroNetwork,
        mnemonic
    });
    const keys = {
        privateSpend: await wallet.getPrivateSpendKey(),
        privateView: await wallet.getPrivateViewKey(),
        publicSpend: await wallet.getPublicSpendKey(),
        publicView: await wallet.getPublicViewKey(),
    }
    const address = await wallet.getPrimaryAddress();

and send some funds to the address via the faucet.

Now I'm trying to connect to the test account via a public node (one from here, should be ok for testing) and I'm stuck. To give a more complete idea, I'm trying to get the balance of the account for which I have creds.

monero-javascript looks like a right tool for that, but I don't get it: here are my attempts based on the docs:

// attempt 1, RPC wallet
const nodeUrl = ... // taken from https://monero.fail for quick dev, worked for getBlockCount RPC (see https://monero.stackexchange.com/a/13549/14510)
const walletRpc = await monerojs.connectToWalletRpc(nodeUrl);
await walletRpc.createWallet({ // *
    // networkType: moneroNetwork,
    mnemonic,
});
// failes with Method not found (at line *) despite it's almost literally an example from docs

// attempt 2, adapted from the other example
const walletFull = await monerojs.createWalletFull({
    networkType: moneroNetwork,
    mnemonic,
    // server: connection
    serverUri: nodeUrl
})
// call fails with "The URL must be of scheme file"

// attempt 3, based on https://github.com/monero-ecosystem/monero-javascript/blob/master/docs/developer_guide/connection_manager.md
const connectionManager = new monerojs.MoneroConnectionManager();
const connection = new monerojs.MoneroRpcConnection(nodeUrl);
connectionManager.setConnection(connection);
await connectionManager.checkConnection();
console.log("Connection manager is connected: " + connectionManager.isConnected());
console.log("Connection is online: " + connectionManager.getConnection().isOnline());
console.log("Connection is authenticated: " + connectionManager.getConnection().isAuthenticated());
/* logs 
Connection manager is connected: true
Connection is online: true
Connection is authenticated: true
   but.. now what? How to get things from wallet?

   I've also tried to create wallet like above after established connection and tried

       const transfers = await wallet.getTransfers();

   but it fails with "Not supported" (like when without connection)
*/

Another libs also don't seem to make an attempt to cover this case in their docs, for instance monero-nodejs starts with create_wallet (generates mnemonic) and doesn't provide examples about "recovering" wallet from mnemonic.

Does anyone know how to connect to a wallet by a given mnemonic? Or at least how to get an account balance by mnemonic?

(deterministic style is implied, private view key is supposed to be derived from private spend key)

1 Answer 1

1

Does anyone know how to connect to a wallet by a given mnemonic? Or at least how to get an account balance by mnemonic?

Your mnemonic words are for restoring a wallet. Not for interacting (such as querying balance) with your wallet.

const nodeUrl = ... // taken from https://monero.fail for quick dev, worked for getBlockCount RPC (see https://monero.stackexchange.com/a/13549/14510)
const walletRpc = await monerojs.connectToWalletRpc(nodeUrl);

connectToWalletRpc(...) connects to an instance of monero-wallet-rpc, not an instance of monerod. Public nodes (as listed on https://monero.fail) are instances of monerod, not wallets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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