2

Here is my code:

const Monero = require('monerojs');

var daemonRPC = new Monero.daemonRPC({ autoconnect: true })
.then((daemon) => {
    daemonRPC = daemon; // Store daemon interface in global variable

    const walletRPC = new Monero.walletRPC() // Connect with defaults
    .then(wallet => {
        walletRPC = wallet;
        walletRPC.create_wallet('monero_test_wallet', '')
        .then(new_wallet => {
            walletRPC.open_wallet('monero_test_wallet', '')
            .then(wallet => {
                walletRPC.getaddress()
                .then(balance => {
                    console.log(balance);
                })
                .catch(err => {
                    console.error(err);
                });
            })
            .catch(err => {
                console.error(err);
            });
        })
        .catch(err => {
            console.error(err);
        });
    });
})
.catch(err => {
    throw new Error(err);
});

And my error:

(node:8373) UnhandledPromiseRejectionWarning: Failed to autoconnect to wallet
(node:8373) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8373) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I'm a newbie, so help would really be appreciated. Thank you so much in advance!

1

As you are not specifying the wallet details (port, host etc), that library uses the defaults:

class walletRPC {
  constructor(hostname = '127.0.0.1', port = 28083, user = undefined, pass = undefined, protocol = 'http', network = 'mainnet') {

Therefore, you would need to have started the monero-wallet-rpc, on the same host, with something like:

monero-wallet-rpc --rpc-bind-port 28083 \
    --disable-rpc-login --wallet-file your-wallet --password your-password

Or to start without an initial wallet like:

monero-wallet-rpc --rpc-bind-port 28083 \
    --disable-rpc-login --wallet-dir /some/path
  • I'm confused by this because I create a wallet, don't I? line 10 calls Monero.create_wallet(...), so what wallet would I provide? the name of the one I create? in which case what password would go with that? – Confused ArchMonero Dev May 30 at 20:13
  • after running it with a test-wallet created using ./monero-wallet-cli, I got this response 2019-05-30 20:14:58.356 0x7fffab02d380 ERROR wallet.wallet2 src/wallet/wallet2.cpp:2540 Blocks start before blockchain offset: 0 1775600 2019-05-30 20:14:58.415 0x7fffab02d380 ERROR wallet.wallet2 src/wallet/wallet2.cpp:2059 !m_blockchain.is_in_bounds(current_index). THROW EXCEPTION: error::out_of_hashchain_bounds_error 2019-05-30 20:14:59.469 0x7fffab02d380 ERROR wallet.wallet2 src/wallet/wallet2.cpp:2720 m_blockchain.size() != stop_height. THROW EXCEPTION: error::wallet_internal_error – Confused ArchMonero Dev May 30 at 20:16
  • You can start the wallet RPC like: monero-wallet-rpc --rpc-bind-port 28083 --disable-rpc-login --wallet-dir /some/path if you want to start it without a wallet. – jtgrassie May 30 at 20:24
  • 1
    this is all excellent, thank you so much @jtgrassie – Confused ArchMonero Dev May 31 at 5:03
  • 1
    I just handed in my project today, it works great. Thank you so much—I love stackexchange so goddamn much @jtgrassie – Confused ArchMonero Dev Jun 18 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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