Official forum for Utopia Community

You are not logged in.

#1 2021-11-12 18:24:52

Registered: 2021-09-20
Posts: 28

Utopia API + Node.js example

Good day to all. I am a regular user of utopia. In the process of using utopia, I came up with ideas that I would like to implement using the utopia API. I don't have a lot of programming experience, and I ran into certain problems when interacting with the API. Therefore, I will post here an example of code in node.js that can help people like me in the future.

This is a simple example, how I called the getMiningBlocks() function, and then display the last data.

const got = require('got');

got.post('', {
    json: {

        method: 'getMiningBlocks',
        token: 'yourtoken'

    } , responseType: 'json'
}).then( response => {

    console.log(response.body['result'][response.body['result'].length - 1]);



  dateTime: '2021-11-12T17:35:04.417Z',
  id: 69490,
  involvedIn: true,
  involvedInCount: 15,
  numberMiners: 28716,
  price: 0.003343083

In got.post, pay attention to which port you are referring to (I use 20010) and which protocol (I use http).

You can even try it on Windows.
Installing a headless version of utopia on linux doesn't even bother you.
In order to try enough for you, just open Utopia, go to the API menu and enable it. Of course, before that you need to download the nodejs and npm package "got"

Thank you for your attention, I hope I can help someone

If you have any questions, my public key is:


#2 2021-11-15 05:06:54

Registered: 2021-11-13
Posts: 2

Re: Utopia API + Node.js example

I will complete the topic by accessing the API with the .NET platform in the C # language. The console program displays the result of the getProfileStatus function (one of the APIs), based on which it is easy to implement others.

using System;
using System.Text;
using System.Net;

WebRequest request = WebRequest.Create("");
request.Method = "POST";
String mes1 = @"{""method"": ""getProfileStatus"", ""token"": ""7632261400226A4AEBF76EA4AD69CFC8""}";
Byte[] b = Encoding.UTF8.GetBytes(mes1);
string s = null;
Encoding enc8 = Encoding.UTF8;
s = enc8.GetString(b);
request.ContentLength = b.Length;
request.ContentType = "application/json; charset=utf-8";
Stream dataStream = request.GetRequestStream();
dataStream.Write(b, 0, b.Length);
WebResponse response = request.GetResponse();
using (dataStream = response.GetResponseStream())
    StreamReader reader = new StreamReader(dataStream);
    string str = reader.ReadToEnd();

You just need to replace the port and token with your own. good luck writing programs!


Board footer

Powered by FluxBB