-
Notifications
You must be signed in to change notification settings - Fork 3
API Requests (GET, POST)
Chain of Industry edited this page Sep 20, 2022
·
7 revisions
Elrond Network privides free to use API to interact wiht the blockchain. The API is built to allow you to create apps or integrations quickly and easily.
The official APIs and docs can be found here:
https://api.elrond.com/
https://gateway-docs.elrond.com/
Note: If you are using devnet or testnet to develop and debug your app use the devnet or testnet APIs accordingly.
//construct the url for the Get request
string url = "https://devnet-api.elrond.com/accounts/erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf";
//make the Get request
ElrondUnityTools.Manager.GetRequest(url, CompleteMethod);
//receive the result inside Complete Method
private void CompleteMethod(ElrondUnityTools.OperationStatus operationStatus, string message, string resultJson)
{
if(operationStatus == ElrondUnityTools.OperationStatus.Complete)
{
Debug.Log(resultJson);
}
else
{
Debug.LogError(message + " " + resultJson);
}
}
The result will always be a json file. In this case it looks like this:
{"address":"erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf","balance":"213000000000000000","nonce":0,"shard":1,"rootHash":"Z/OOLNyL3UhuI+zK98Mq2cW4ypMy0OSHCYuUe0J4fSI=","txCount":80,"scrCount":0,"developerReward":"0"}
url = "https://devnet-gateway.elrond.com/transaction/cost";
string json = "{" +
"\"nonce\":0," +
"\"sender\":\"erd1lgp3ezf2wfkejnu0sm5y9g4x3ad05gr8lfc0g69vvdwwj0wjv0gscv2w4s\"," +
"\"receiver\":\"erd1jza9qqw0l24svfmm2u8wj24gdf84hksd5xrctk0s0a36leyqptgs5whlhf\"," +
"\"value\":\"1000000000000000\"," +
"\"gasPrice\":1000000000," +
"\"gasLimit\":89000," +
"\"data\":\"WW91IHNlZSB0aGlzPw==\"," +
"\"chainId\":\"D\"," +
"\"version\":1," +
"\"signature\":\"72ddcb105778051ea2a6f92b3869e2110d50f708708a2a3fe842014c062152c8aff78dae39868d97d25831915d3c60f4acfc749dfa8bdfa395f3769d2e231a05\"" +
"}";
ElrondUnityTools.Manager.PostRequest(url, json, CompleteMethod);