Official forum for Utopia Community
You are not logged in.
Pages: 1
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
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
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
nice
Offline
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
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
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
Pages: 1