Access AION through REST API — AION GraphQL now supports REST APIs

Satya
4 min readNov 15, 2018

In this post, I am going to talk about new REST API support in AION GraphQL project. The goal of AION GraphQL project is to provide a GraphQL API server implementation for AION blockchain and use the power of GraphQL queries to access AION blockchain.

GraphQL is a more efficient, powerful and flexible alternative to REST. It was publicly release by Facebook in 2015. Since then, there’s been a flurry of activity, and the open-source ecosystem around GraphQL has grown rapidly.

But many enterprises are still trying to migrate from SOAP based web-service to REST. Also, many developers may not be familiar with GraphQL.

So why not a REST Api layer for AION blockchain ?

AION GraphQL project now provides REST API layer for AION blockchain. The initial implementation is now available in the latest version of AION GraphQL. (v0.4.0)

AION GraphQL project uses AION Java RPC API internally and all the methods in java rpc are also there as GraphQL API. That means, all the building blocks of getting data from AION blockchain are there.

The new REST API layer sits on top of the same building blocks (services) and provides REST API interface.

These apis are HATEOAS compatible. So along with the content, the api returns links to other related contents which can be used by the client.

To know more about HATEOAS driven REST service, check this url https://restfulapi.net/hateoas/

The REST APIs are still under active development and more APIs will be added in next release.

If you don’t want to enable REST API in your deployment, it can be disabled by setting the following property to false in application.yml or as environment variable.

rest:
enable:
true

Swagger API Explorer :

Similar to Playground UI for GraphQL API, you can explore and try all supported AION REST APIs in the following embedded swagger ui.

Few Major REST APIs:

> Get blocks / block

> Get Transactions / Transaction

> Send a encoded Sign transaction to Kernel

> Get Account by address

> Get Network Information

More apis are coming soon…

Examples

> Get last 10 Blocks

“https://api.aion-graphql.com/rest/v1/blocks?first=10”

Response:

Check the links section in the following output for HATEOAS compatible links.

{
"_embedded" : {
"blockList" : [ {
"number" : 1688984,
"nrgConsumed" : 21000,
"nrgLimit" : 15013596,
"bloom" : "0000000000000000000000000000000000000000000000000000000000000000000..",
"extraData" : "7c61696f6e2d4c4f56457c45717521684024232d53304c7574696f6e7c584f7c",
"solution" : "003f880371194fc03c1df2067dd9ea298432b9f8789834d99eb13b19f4a42b92e63...",
"hash" : "1cb816c85d98107962a057c3d5246262dabe72f12ba762e885132bce3acbd676",
"parentHash" : "b1c5b7a72271c9822f5be444c378920ac20ffdc1ebf7ea89a76f60bd1fb6234a",
"nonce" : 28114070494753651452329429831821319423846923767084848861637719025730117959680,
"difficulty" : 16868375,
"totalDifficulty" : 22602214146386,
"minerAddress" : "a0a1e55cbbffc99d9dcaf56e5350847267471cd6d69d4dead14953e5e82d97bf",
"stateRoot" : "a2a2806f7580a634aec6bbf5d6c3f4d843b00b30426f23d00b53aa3a2a4ea7f6",
"txTrieRoot" : "9a08a53f50b001852d6468f2717289eaaf8f779679c4842e67df03fb19cd7c9f",
"size" : 2112,
"txDetails" : [ {
"from" : "a099688bb19051b38c846580600812d095f89cfff7abc17ab6c4af63e408f2f1",
"to" : "a01779ba96290a3416563b4d32a7e012fa559a2f5b307b3a35dbdaf894fd55fc",
"txHash" : "a72bb4460b16c2dd582b61099d834709223a7f46b971132e114e5c5aa0caf970",
"value" : 677709048566234400,
"nonce" : 4926,
"nrgConsumed" : 21000,
"nrgPrice" : 10000000000,
"data" : "",
"txIndex" : 0,
"contract" : "",
"timestamp" : 1542297241718405,
"error" : "",
"blockNumber" : 1688984,
"blockHash" : "1cb816c85d98107962a057c3d5246262dabe72f12ba762e885132bce3acbd676",
"_links" : {
"self" : {
"href" : "https://api.aion-graphql.com/rest/v1/transactions/a72bb4460b16c2dd582b61099d834709223a7f46b971132e114e5c5aa0caf970"
},
"from" : {
"href" : "https://api.aion-graphql.com/rest/v1/accounts/a099688bb19051b38c846580600812d095f89cfff7abc17ab6c4af63e408f2f1"
},
"to" : {
"href" : "https://api.aion-graphql.com/rest/v1/accounts/a01779ba96290a3416563b4d32a7e012fa559a2f5b307b3a35dbdaf894fd55fc"
}
}

} ],
"blockTime" : 30,
"timestamp" : 1542297252,
"_links" : {
"self" : {
"href" : "https://api.aion-graphql.com/rest/v1/blocks/1688984"
}
}
}, {
"number" : 1688983,
"nrgConsumed" : 0,
"nrgLimit" : 14998949,
...

> Get last 5 transactions

“https://aion-graphql.com/rest/v1/transactions?first=5”

Response:

{
"_embedded" : {
"txDetailsList" : [ {
"from" : "a04f0117864ccf5013861a89f08c6fc790284d72356c8a362025d31b855ed6ed",
"to" : "a0c00cfc4c53bb6d49f385b91f58a23dd7b1dc024976b391bb8b81eb9e8801ab",
"txHash" : "614fae89df31ef9081c3820ca918a79fa07a487c95e7d3c49086ddc16eef1551",
"value" : 4810581446373384000,
"nonce" : 639,
"nrgConsumed" : 21000,
"nrgPrice" : 10000000000,
"data" : "",
"txIndex" : 0,
"contract" : "",
"timestamp" : 1542297819,
"error" : "",
"blockNumber" : 1689034,
"blockHash" : "7c2b9af46b82b9156c280d350bf6f7cf40ffe443e482ce2948a1e238acd35618",
"_links" : {
"self" : {
"href" : "https://api.aion-graphql.com/rest/v1/transactions/614fae89df31ef9081c3820ca918a79fa07a487c95e7d3c49086ddc16eef1551"
},
"from" : {
"href" : "https://api.aion-graphql.com/rest/v1/accounts/a04f0117864ccf5013861a89f08c6fc790284d72356c8a362025d31b855ed6ed"
},
"to" : {
"href" : "https://api.aion-graphql.com/rest/v1/accounts/a0c00cfc4c53bb6d49f385b91f58a23dd7b1dc024976b391bb8b81eb9e8801ab"
}
}

}, {
"from" : "a0a56ed42b94e513da53273dca7dc1002a99f402e4e6478baa1edbf295e56337",
"to" : "a0c00cfc4c53bb6d49f385b91f58a23dd7b1dc024976b391bb8b81eb9e8801ab",
"txHash" : "e68ce89d0040ee94f099349dfc1eab20d5c8341e036dc06aed00466f933fd6b1",
"value" : 1316933011836606500,
"nonce" : 510,
"nrgConsumed" : 21000,
"nrgPrice" : 10000000000,
"data" : "",
"txIndex" : 0,
"contract" : "",

> Post a signed transaction

“POST https://api.aion-graphql.com/rest/v1/transactions“

Request body: <encoded signed data>

Security

AION GraphQL doesn’t implement any security layer yet. Ideally it will be accessed through a API gateway and all common functionalities like authentication, logging, rate limiting will be provided by the API Gateway. One of the popular opensource API gateway is Kong.

But in future, we may plan a default out of box authentication layer which can be enable or disabled through configuration.

If you are following AION GraphQL project or planning to use it in your project, I would love to hear your feedback or suggestion.

Check this space for more APIs …

Project: https://aion-graphql.com

GitHub: https://github.com/satran004

Swagger UI: https://api.aion-graphql.com/swagger-ui.html

GraphQL Playground: https://api.aion-graphql.com/playground.html

--

--