0

I'm exploring what APIs are available to explore mainnet and testnet and a small task I'm trying to do is to get block height of testnet.

Docs about networks tell that there's a testnet open node: monero-testnet.exan.tech:28081.

Looking at the basic example of monero-javascript, I see that the following code should probably be enough:

// import library
const monerojs = require("monero-javascript");

// inside an async function const daemon = await monerojs.connectToDaemonRpc("http://localhost:38081", "superuser", "abctesting123"); const height = await daemon.getHeight();

Well, I'm not sure about login and passphrase, but I tried

const daemon = await monerojs.connectToDaemonRpc("http://monero-testnet.exan.tech:28081", "superuser", "abctesting123");

and got

TypeError: The URL must be of scheme file

(same for http://monero-testnet.exan.tech:28081/json_rpc)

What exactly am I doing wrong? Is monero-testnet.exan.tech:28081 an endpoint for json-rpc? Are json-rpc and daemon-rpc the same? Is there a public endpoint that I can use with monerojs.connectToDaemonRpc at all? In fact any pointer to get block height via some public API is welcome.

YakovL
  • 105
  • 6

2 Answers2

0

Well, the solution I've come up with is based on this QA (actually, almost a copy-paste):

const RpcClientClass = require("monero-rpc-client");
const nodeAddress = ... // see nodes at https://monero.fail for quick dev
const rpcClient = new RpcClientClass(nodeAddress);
rpcClient.getBlockCount()
    .then(result => console.log(result.result.count));

This is an example of JSON RPC call of one of the daemon-rpc methods.

YakovL
  • 105
  • 6
0

Was able to get the original code working on my system and fix the

TypeError: The URL must be of scheme file

error by switching to WSL (Windows Subsystem for Linux) before running the code and updating to latest node version

Ade
  • 1
  • 1