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.

2
  • Start by using a node that's online: monero.fail/?nettype=testnet
    – jtgrassie
    Mar 23, 2022 at 18:13
  • @jtgrassie thanks, I've figured that already, will post the overall solution as an answer
    – YakovL
    Mar 23, 2022 at 18:15

2 Answers 2

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.

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

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.