Skip to content

Instantly share code, notes, and snippets.

@evias
Last active August 26, 2018 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evias/effd71fbb3e357d7da5f26fd2b4f9d58 to your computer and use it in GitHub Desktop.
Save evias/effd71fbb3e357d7da5f26fd2b4f9d58 to your computer and use it in GitHub Desktop.
retrieve last block from the NEM blockchain using the Node.js NEM-sdk
// include the NEM-sdk package in your package.json first.
// nem-sdk: npmjs.com/package/nem-sdk
let nem_ = require("nem-sdk").default;
let connectedNode = nem_.model.objects.create("endpoint")("http://bigalice2.nem.ninja", "7890");
nem_.com.requests.chain.lastBlock(connectedNode)
.then(function(err, block)
{
if (! err && block) {
console.log("NEM Testnet blockchain last block: " + JSON.stringify(block));
}
});
@r9danny16
Copy link

typing this code, I got the following error msg :

Invalid URI ":7890/chain/last-block"

@evias
Copy link
Author

evias commented Aug 26, 2018

This means that you probably modified the URL set in connectNode. It works fine for me after running it in a javascript console with nem-sdk available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment