uTalk

Official forum for Utopia Community

You are not logged in.

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

youtube
Member
Registered: 2021-09-20
Posts: 30

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('http://127.0.0.1:20010/api/1.0/', {
    json: {

        method: 'getMiningBlocks',
        token: 'yourtoken'

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

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

    }
)

data

{
  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:
F89309DC5E7E153F641BD2027B1541498415231F41B9262D2007C0769BF86C1F

Offline

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

germanmsh
Member
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("http://127.0.0.1:20001/api/1.0");
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);
Console.WriteLine(s);
request.ContentLength = b.Length;
request.ContentType = "application/json; charset=utf-8";
Stream dataStream = request.GetRequestStream();
dataStream.Write(b, 0, b.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
using (dataStream = response.GetResponseStream())
{
    StreamReader reader = new StreamReader(dataStream);
    string str = reader.ReadToEnd();
    Console.WriteLine(str);
}
response.Close();
Console.ReadKey();

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

Offline

#3 2021-12-05 12:59:35

SGL
Member
From: Infospace
Registered: 2021-12-05
Posts: 70

Re: Utopia API + Node.js example

Can you make it up and put it on Github? Let's add to the API examples


Crypton/UUSD donation for new developments: F50AF5410B1F3F4297043F0E046F205BCBAA76BEC70E936EB0F3AB94BF316804

Offline

#4 2022-11-23 16:27:11

bicpter
Member
Registered: 2022-05-09
Posts: 9

Re: Utopia API + Node.js example

nice

Offline

#5 2022-12-27 17:45:46

Kelechi
Member
Registered: 2022-12-25
Posts: 2,692

Re: Utopia API + Node.js example

It's actually a good thing to donate but right now what's Utopia p2p most concentrated on to develop, like what's that development going into right now?

Offline

#6 2023-05-17 22:33:08

Comrade
Member
From: Utopia App Client
Registered: 2022-12-30
Posts: 2,036

Re: Utopia API + Node.js example

We should  know Utopia operations are crucial and has a enhancing website security in which it  ensuring data integrity, and protecting sensitive information which is same as Node.js.which have JavaScript runtime environment, provides a robust crypto module that allows developers to perform various cryptographic functions.

Offline

#7 2024-02-18 21:57:34

Lanistergame2
Member
Registered: 2022-12-25
Posts: 2,058

Re: Utopia API + Node.js example

documented Utopia API for developers to interact with. Utopia is a decentralized, privacy-focused ecosystem that includes features like messaging, email, and more.
If there has been a development since then and an API has been released, you should refer to the official Utopia documentation or developer resources for the most

Offline

#8 2024-05-30 22:27:03

Kelechi
Member
Registered: 2022-12-25
Posts: 2,692

Re: Utopia API + Node.js example

Next, you'll need to install any necessary dependencies. If the Utopia API has an npm package, you can install it using npm or yarn. Otherwise, you may need to use the axios package to make HTTP requests to the API.

Offline

#9 2024-06-24 21:55:27

Lanistergame2
Member
Registered: 2022-12-25
Posts: 2,058

Re: Utopia API + Node.js example

Step 1: Set up a new Node.js project.
Step 2: Install the axios package.
Step 3: Create index.js and add the script to make a GET request to the Utopia API.
Step 4: Run the script.
This example should get you started with using the Utopia API in a Node.js environment.

Offline

#10 2024-07-04 22:02:25

Kelechi
Member
Registered: 2022-12-25
Posts: 2,692

Re: Utopia API + Node.js example

To integrate the Utopia API with a Node.js application, you'll typically need to perform the following steps:
Se up a Node.js project.
Install necessary dependencies.
Write code to interact with the Utopia API.

Offline

#11 2024-07-04 22:15:08

Lanistergame2
Member
Registered: 2022-12-25
Posts: 2,058

Re: Utopia API + Node.js example

Two example functions (getUtopiaData and postUtopiaData) demonstrate how to fetch and send data to the Utopia API.
Example Usage: The example usage at the bottom calls these functions, showing how you might use them in a real application.

Offline

#12 2024-07-08 21:11:19

Kelechi
Member
Registered: 2022-12-25
Posts: 2,692

Re: Utopia API + Node.js example

These examples assume a RESTful API and that the Utopia API requires an API key for authentication. Adjust the code based on the actual requirements of the Utopia API.

Offline

#13 2024-07-08 21:42:40

Lanistergame2
Member
Registered: 2022-12-25
Posts: 2,058

Re: Utopia API + Node.js example

Axios: In both examples, axios is used to handle HTTP requests. Install it with npm install axios.
API_URL: Replace the placeholder URLs with actual endpoints from the Utopia API.

Offline

#14 2024-07-08 21:53:08

Detroit
Member
Registered: 2022-12-27
Posts: 1,844

Re: Utopia API + Node.js example

To configure qt.conf to make a Qt application work in a different location, you can adjust the configuration to specify paths for plugins, libraries, and other resources. This is useful if you want to move a Qt application to a different directory structure without modifying the application code itself.

Offline

Board footer

Powered by FluxBB