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!

jtgrassie
  • 19,111
  • 4
  • 14
  • 51

1 Answers1

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
jtgrassie
  • 19,111
  • 4
  • 14
  • 51
  • 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 '19 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 '19 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 '19 at 20:24
  • what would the /some/path be? (I'm sorry I really don't know what I'm doing) – Confused ArchMonero Dev May 30 '19 at 20:38
  • it only spit out one error—thank you guys! 019-05-30 20:55:09.820 [RPC0] ERROR wallet.wallet2 src/wallet/wallet2.cpp:4585 !is_keys_file_locked(). THROW EXCEPTION: error::wallet_internal_error – Confused ArchMonero Dev May 30 '19 at 20:55
  • /some/path needs to be a directory on your system that will be used when you create a wallet. It must exist and be writable. – jtgrassie May 30 '19 at 21:29
  • 1
    this is all excellent, thank you so much @jtgrassie – Confused ArchMonero Dev May 31 '19 at 05:03
  • No problem. Glad to help. – jtgrassie May 31 '19 at 10:07
  • 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 '19 at 02:27