Comment on page
Examples
It shows examples of using the Token/Wallet/Block APIs.
All APIs use HTTP POST to send and receive JSON data.
Users must have an address to store their tokens, like a bank account in a bank. To create an address, request as below.
{
"jsonrpc": "2.0",
"id": "1234",
"method": "createAddress",
"params": {
"addInfo": "My first address"
}
}
- "jsonrpc" must be exactly "2.0".
- "id" is an identifier established by the client application. Must contain a string.
- "method" is a name of method to be invoked. To create an address, "createAddress" is used.
- "params" holds the parameter values to be used during the invocation of the method. "addInfo" is the address name.
Response:
{
"jsonrpc": "2.0",
"id": "1234",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"address": "0x841dd0a424ba0ab63950a4c8ad11b33f34deac64",
"mnemonic": "miracle anchor zebra brush talent broom pig broom news hammer suit brick",
"secretKey": "d0c48b4d6972bf8d4110f81d5dd8ac1c"
}
}
}
- "id" is the same value of the request.
- Address "0x841dd0a424ba0ab63950a4c8ad11b33f34deac64" is created.
- "mnemonic" is keywords used when restoring a secret key when it is lost. The user should record this somewhere for later.
- "secretKey" should be saved in the client application. If you lose it, you cannot use this address.
If you want to check your address,
{
"jsonrpc": "2.0",
"id": "1235",
"method": "getAddressInfo",
"params": {
"address": "0x841dd0a424ba0ab63950a4c8ad11b33f34deac64"
}
}
Response:
{
"jsonrpc": "2.0",
"id": "1235",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"address": "0x841dd0a424ba0ab63950a4c8ad11b33f34deac64",
"addInfo": "My first address"
}
}
}
Tokens are identified by contract address. Token generation is managed by the server, not by the client. The following tokens are defined.
Token symbol | Contract address | Description |
---|---|---|
NLP | 0xad07f52767774df51efa2433c79e90e954db5e7c | The utility token for Nuri |
LMTL | 0x7531bd63867fe3eded80dc875688e4c038575451 | LMTLS |
MST | 0x5f748cff221bf63bdadf33cd2678093930e7fb2a | Medical service token |
MDT | 0x3ff720bf49f69a61fd2c9a19a5b9a33ed5a59555 | Medical DAO token |
Token transfer takes place in 4 steps.
First, a temporary key is issued to secure the transfer.
{
"jsonrpc": "2.0",
"id": "1234",
"method": "net_getTempKey",
"params": {
"address": "0x5f619702528e9de7f5a4a233cd1896902385e705",
"keyType": "transfer"
}
}
- "address" is the your sender address.
- "keyType" should be "transfer".
Response:
{
"jsonrpc": "2.0",
"id": "1234",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"tempKey": "c3b915aba82d31aa7f505739ee323db0"
}
}
}
- "tempKey" is used during transfer.
Second, create the signature of the message to secure the message.
{
"jsonrpc": "2.0",
"id": "1234",
"method": "signData",
"params": {
"address": "0x841dd0a424ba0ab63950a4c8ad11b33f34deac64",
"data": "0ef6b88023386ac2691ebc50e6ab8c651326524ac7932b2c88c8349cc0b5d21f",
"tempKey": "c3b915aba82d31aa7f505739ee323db0",
"hashKey": "5df34c6abc72e6d96e4499f6b1999e43c146a43000813eb7154c87c1eb3dc619"
}
}
- "address" is the sender address.
- "tempKey" is the temp key issued in the first step.
- "hashKey" is the hash value made from the the temp key and the secret key of the sender address. For example, hash(['c3b915aba82d31aa7f505739ee323db0', 'd0c48b4d6972bf8d4110f81d5dd8ac1c']) => '5df34c6abc72e6d96e4499f6b1999e43c146a43000813eb7154c87c1eb3dc619'. The hash function is defined below in Dart. This function will be used repeatedly.
/// Dart
import 'package:crypto/crypto.dart';
String hash(List<String> v) => sha256.convert(utf8.encode(v.join('|'))).toString();
- "data" is the hash value made from the contract address, your address (sender), the recipient address, the transfer amount, the temp key, and the hash key. For example, hash(['0x1a007ca3d881c14269f956c6e4b734095bf450a7', '0x841dd0a424ba0ab63950a4c8ad11b33f34deac64', '0x191f06333602d2f5296e1aa83e3166454032adab', "1", "c3b915aba82d31aa7f505739ee323db0", "5df34c6abc72e6d96e4499f6b1999e43c146a43000813eb7154c87c1eb3dc619"]) => '0ef6b88023386ac2691ebc50e6ab8c651326524ac7932b2c88c8349cc0b5d21f'
Response:
{
"jsonrpc": "2.0",
"id": "1234",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"signedData": "304502203ee4b7410b058c718ae52423cde25f4df68b4ce49255c4a6f34ae368c3f0a3690221009332445fcb1717588063a098882bc6ff17e887b76f6fac46ca0cfdec0e1e2595"
}
}
}
- "signedData" is used for the signature of the message.
Third, transfer a token.
{
"jsonrpc": "2.0",
"id": "1234",
"method": "erc20_transfer",
"params": {
"contractAddress": "0x1a007ca3d881c14269f956c6e4b734095bf450a7",
"sender": "0x841dd0a424ba0ab63950a4c8ad11b33f34deac64",
"toAddress": "0x191f06333602d2f5296e1aa83e3166454032adab",
"amount": "1",
"tempKey": "c3b915aba82d31aa7f505739ee323db0",
"hashKey": "5df34c6abc72e6d96e4499f6b1999e43c146a43000813eb7154c87c1eb3dc619",
"signature": "3044022036d634a588a4582539465d8c4849303ed5acee11ba6e3772649ba6e442c1d25c022016902d4dd83bcedca25ef7e4e530d19f08afba77a1c2d10fe25d225ae2eb7f79",
"comment": "Transfer"
}
}
- "signature" is the signed data in the second step.
- "comment" is not included in the signature.
Response:
{
"jsonrpc": "2.0",
"id": "57096",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"transactionId": "0x50d0b07cd332b08b15ec071c9bf00cd6b926f43b2ffd1bc62e7f3254033e94ee"
}
}
}
- "transactionId" is returned.
Forth, token transfer takes time. Wait until it is written to the blockchain.
{
"jsonrpc": "2.0",
"id": "57266",
"method": "net_getTransactionStatus",
"params": {
"transactionId": "0x50d0b07cd332b08b15ec071c9bf00cd6b926f43b2ffd1bc62e7f3254033e94ee"
}
j
Response:
{
"jsonrpc": "2.0",
"id": "57266",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"status": -1,
"revertReason": ""
}
}
}
Or
{
"jsonrpc": "2.0",
"id": "59336",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"status": 1,
"revertReason": ""
}
}
}
- A status of -1 indicates that the transaction is still in progress, and 0 or 1 indicates that the transaction is complete. (1: success, 0: error).
Waits by periodically calling net_getTransactionStatus until status is not -1.
Check the balance of a specific token in the address.
{
"jsonrpc": "2.0",
"id": "37026",
"method": "erc20_getBalance",
"params": {
"contractAddress": "0x1a007ca3d881c14269f956c6e4b734095bf450a7"
"address": "0x841dd0a424ba0ab63950a4c8ad11b33f34deac64",
}
}
Response:
{
"jsonrpc": "2.0",
"id": "37026",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"balance": "99"
}
}
}
The ERC721 token creation, minting, and transfer are managed by the server. The client only handlles token approval. The following tokens are defined.
Token symbol | Contract address | Description |
---|---|---|
NFNL | 0xa408c647676f01c1463174019ddacdc49837097b | NFT for Nuri |
NFMS | 0x17e8b326d80b286dc11761add1a24a18493f6b85 | NFT for medical service |
When you mint the product through the server (a separate API will be provided), you will receive the contract address and token ID.
In order to put a product on the NFT market, the authority of the product must be delegated to the market. At this time, the approval method is used. The approval method is called similar to the transfer method.
First, get a temporary key.
{
"jsonrpc": "2.0",
"id": "53494",
"method": "net_getTempKey",
"params": {
"address": "0xd839a7e8872a2624fc9d84eee63bb1eca8ee9be9",
"keyType": "approve"
}
}
- "address" is the address where your NFT is stored.
- "keyType" should be "approve".
Response:
{
"jsonrpc": "2.0",
"id": "53494",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"tempKey": "ae1b64e6a1a29d9b91ef7515dfe74c4d"
}
}
}
Second, get the message signature.
{
"jsonrpc": "2.0",
"id": "54079",
"method": "signData",
"params": {
"hashKey": "02d8168679b03d74902159e2e1782d2a0644408acb01791023c858dc8788df11",
"address": "0xd839a7e8872a2624fc9d84eee63bb1eca8ee9be9",
"data": "5b69d60a7fec498b9f3d24ef06b4cb323c7d0606e4606edad19065c3c024f578",
"tempKey": "ae1b64e6a1a29d9b91ef7515dfe74c4d"
}
}
- "hashKey" is the hash value made from the the temp key and the secret key of the your address. For example, hash(['ae1b64e6a1a29d9b91ef7515dfe74c4d', 'b5dc981ece0925ecf56e490727bce577']) => '02d8168679b03d74902159e2e1782d2a0644408acb01791023c858dc8788df11'. "b5dc981ece0925ecf56e490727bce577" is the secret key of the your address.
- "data" is the hash value made from the contract address, your address (sender), the market address (spender), the token ID, the temp key, and the hash key. For example, hash(['0xa408c647676f01c1463174019ddacdc49837097b', '0xd839a7e8872a2624fc9d84eee63bb1eca8ee9be9', '0x6a39630bd5986e73fe181938c6097958127c16c4', "2", "ae1b64e6a1a29d9b91ef7515dfe74c4d", "02d8168679b03d74902159e2e1782d2a0644408acb01791023c858dc8788df11"]) => '5b69d60a7fec498b9f3d24ef06b4cb323c7d0606e4606edad19065c3c024f578'. "0x6a39630bd5986e73fe181938c6097958127c16c4" is the market address.
Response:
{
"jsonrpc": "2.0",
"id": "54079",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"signedData": "3046022100c21b658831e1d8955fd92fb937c0c5d39ceb2f72522a0667fdff685764920478022100fa38a36d9e2b6cac80e39723ac79af4386ad466e1afd019a50149588c3a78de2"
}
}
}
Third, delegate the ownership of the product to the market.
{
"jsonrpc": "2.0",
"id": "54157",
"method": "erc721_approve",
"params": {
"hashKey": "02d8168679b03d74902159e2e1782d2a0644408acb01791023c858dc8788df11",
"tokenId": "2",
"sender": "0xd839a7e8872a2624fc9d84eee63bb1eca8ee9be9",
"spender": "0x6a39630bd5986e73fe181938c6097958127c16c4",
"signature": "3046022100c21b658831e1d8955fd92fb937c0c5d39ceb2f72522a0667fdff685764920478022100fa38a36d9e2b6cac80e39723ac79af4386ad466e1afd019a50149588c3a78de2",
"contractAddress": "0xa408c647676f01c1463174019ddacdc49837097b",
"comment": "Put on the market",
"tempKey": "ae1b64e6a1a29d9b91ef7515dfe74c4d"
}
}
- "sender" is your address which stores your NFT.
- "spender" is the market address.
Response:
{
"jsonrpc": "2.0",
"id": "54157",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"transactionId": "0xf9348011be7423261ca2c74208f876a1a4a3cd6dcd3038414a131bd247d6b783"
}
}
}
Forth, token approval takes time. Wait until it is finished.
{
"jsonrpc": "2.0",
"id": "54238",
"method": "net_getTransactionStatus",
"params": {
"transactionId": "0xf9348011be7423261ca2c74208f876a1a4a3cd6dcd3038414a131bd247d6b783"
}
}
Response:
{
"jsonrpc": "2.0",
"id": "56316",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"status": 1,
"revertReason": ""
}
}
}
- A status of -1 indicates that the transaction is still in progress, and 0 or 1 indicates that the transaction is complete. (1: success, 0: error).
Waits by periodically calling net_getTransactionStatus until status is not -1.
To get a list of swappable tokens, use swap_getPairList. Token swap list management is done by the server.
{
"jsonrpc": "2.0"
"id": "85551",
"method": "swap_getPairList",
}
Response:
{
"jsonrpc": "2.0",
"id": "85551",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": [
{
"pairAddress": "0x294e47341f7da34a6d8187ecbc4ff206d6ca212f",
"token0": "0x0d183c9a4d9b2c503c049ffc687436b35c31ea3a",
"token1": "0x4883c1d966d103485f97f548a0cb1fb117388af0",
"symbol0": "TOK1",
"symbol1": "TOK2",
"amount0": "1",
"amount1": "10"
}
]
}
}
- Swap between TOK1 and TOK2 is possible.
You can get an estimate of the amount you can receive when swapping.
{
"jsonrpc": "2.0",
"id": "86197",
"method": "swap_getAmountOut",
"params": {
"tokenIn": "0x0d183c9a4d9b2c503c049ffc687436b35c31ea3a",
"tokenOut": "0x4883c1d966d103485f97f548a0cb1fb117388af0",
"amountIn": "0.1",
"sender": "0x6a39630bd5986e73fe181938c6097958127c16c4"
}
}
- "tokenIn" and "tokenOut" are the token contract addresses.
- You want to swap "amountIn" from "tokenIn" to "tokenOut".
- "sender" is your address storing "tokenIn".
Response:
{
"jsonrpc": "2.0",
"id": "86197",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"amountIn": "0.1",
"amountOut": "0.405288228265375695"
}
}
}
- You can get 0.405288228265375695 of tokenOut.
To swap tokens, there are two steps.
First, you must entrust (approve) your token. To call this method, as in the case of transfer, the temp key is obtained, the message signature is obtainded, after then the method can is called.
Get a temp key.
{
"jsonrpc": "2.0",
"id": "86255",
"method": "net_getTempKey",
"params": {
"address": "0x6a39630bd5986e73fe181938c6097958127c16c4",
"keyType": "approve"
}
}
- "address" is your address.
- "keyType" should be "approve".
Response:
{
"jsonrpc": "2.0",
"id": "86255",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"tempKey": "b215f78617e0e5559042971c8e284133"
}
}
}
Get the signature of the message.
{
"jsonrpc": "2.0",
"id": "86287",
"method": "signData",
"params": {
"address": "0x6a39630bd5986e73fe181938c6097958127c16c4",
"tempKey": "b215f78617e0e5559042971c8e284133",
"hashKey": "33f82dc02a98428690b41820970bfeefff7294fcb432408ed8ad924baf874fe1",
"data": "d62cd64946e2522dc7963a7bcabf5d927998bbeea10d96732b79aa793ecf9b8a"
}
}
- "hashKey" is hash(temp key, your address's secret key).
- "data" is hash(tokenIn contract address, your address, amount, "tempKey", "hashKey").
Resonse:
{
"jsonrpc": "2.0",
"id": "86287",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"signedData": "304602210088ae728b0bc33b7416d73c4b4e04be59bf9da45ad1037799f1b7e4b49a1a16a4022100da66160775e9a99dbd8e02aae98ad7b0eb45a0c0ab55c9fbe6d604c320a0aa31"
}
}
}
Approve the token amount
{
"jsonrpc": "2.0",
"id": "86354",
"method": "swap_approve",
"params": {
"contractAddress": "0x0d183c9a4d9b2c503c049ffc687436b35c31ea3a",
"sender": "0x6a39630bd5986e73fe181938c6097958127c16c4",
"amount": "0.1",
"comment": "Approve to swap",
"tempKey": "b215f78617e0e5559042971c8e284133",
"hashKey": "33f82dc02a98428690b41820970bfeefff7294fcb432408ed8ad924baf874fe1",
"signature": "304602210088ae728b0bc33b7416d73c4b4e04be59bf9da45ad1037799f1b7e4b49a1a16a4022100da66160775e9a99dbd8e02aae98ad7b0eb45a0c0ab55c9fbe6d604c320a0aa31"
}
}
- "contractAddress" is the tokenIn contract address.
- "sender" is your address.
- "tempKey", "hashKey", and "signature" are obtained in the previous steps.
Response:
{
"jsonrpc": "2.0",
"id": "86354",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"transactionId": "0x0a32339b56022e31aa1f3a5162d4e4a581a3d28505ac7c84b05fdd5c347bb61f"
}
}
}
Wait for it to complete.
{
"method": "net_getTransactionStatus",
"id": "86420",
"jsonrpc": "2.0",
"params": {
"transactionId": "0x0a32339b56022e31aa1f3a5162d4e4a581a3d28505ac7c84b05fdd5c347bb61f"
}
}
Response:
{
"jsonrpc": "2.0",
"id": "89531",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"status": 1,
"revertReason": ""
}
}
}
Second, swap tokens.
Get a temp key.
{
"jsonrpc": "2.0",
"id": "89561",
"method": "net_getTempKey",
"params": {
"address": "0x6a39630bd5986e73fe181938c6097958127c16c4",
"keyType": "swap"
}
}
- "address" is your address.
- "keyType" should be "swap".
Response:
{
"jsonrpc": "2.0",
"id": "89561",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"tempKey": "57a2b588f8b9634f53a322cdf1edfb05"
}
}
}
Get the signature of the message.
{
"jsonrpc": "2.0",
"id": "89597",
"method": "signData",
"params": {
"address": "0x6a39630bd5986e73fe181938c6097958127c16c4",
"hashKey": "829f93bc755e5928a13edb69d9bf81130db4f6d4637c59c2aa9923af9ac1a93e",
"tempKey": "57a2b588f8b9634f53a322cdf1edfb05",
"data": "0758e1bd89b0cb38b38ca6f74e601a3eb258f33eeedcf0ba3531c1d624f6968a"
}
}
- "hashKey" is hash(temp key, your address's secret key).
- "data" is hash(tokenIn amount, tokenOut amount, tokenIn contract address, your address, "tempKey", "hashKey").
Resonse:
{
"jsonrpc": "2.0",
"id": "89597",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"signedData": "3045022100946bd7860fe667b247692d50449135864428c17e0d50e42175a8b701ac8ed11702205a69e0f03684842906aed52b1c030dc686030806926ad1a7c3aa3c80291c37ff"
}
}
}
Swap tokens.
{
"jsonrpc": "2.0",
"id": "89626",
"method": "swap_tokenToToken",
"params": {
"amountIn": "0.1",
"tokenIn": "0x0d183c9a4d9b2c503c049ffc687436b35c31ea3a",
"tokenOut": "0x4883c1d966d103485f97f548a0cb1fb117388af0",
"sender": "0x6a39630bd5986e73fe181938c6097958127c16c4",
"comment": "Swap",
"tempKey": "57a2b588f8b9634f53a322cdf1edfb05",
"hashKey": "829f93bc755e5928a13edb69d9bf81130db4f6d4637c59c2aa9923af9ac1a93e",
"signature": "3045022100946bd7860fe667b247692d50449135864428c17e0d50e42175a8b701ac8ed11702205a69e0f03684842906aed52b1c030dc686030806926ad1a7c3aa3c80291c37ff"
}
}
- "tokenIn" and "tokenOut" are the contract addresses.
- "sender" is your address.
- "tempKey", "hashKey", and "signature" are obtained in the previous steps.
Response:
{
"jsonrpc": "2.0",
"id": "89626",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"transactionId": "0xc0a11b0b743d060672f00bb7c8386af252d793162b6aee233109c2daaf054173"
}
}
}
Wait for it to complete.
{
"jsonrpc": "2.0",
"id": "91789",
"method": "net_getTransactionStatus",
"params": {
"transactionId": "0xc0a11b0b743d060672f00bb7c8386af252d793162b6aee233109c2daaf054173"
}
}
Response:
{
"jsonrpc": "2.0",
"id": "91789",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"status": 1,
"revertReason": ""
}
}
}
{
"jsonrpc": "2.0",
"id": "55900",
"method": "getStakingV1List",
"params": {
"pageNumber": 1,
"pageSize": 10,
"order": 1,
"stakingTimeFilter": 1666000700819,
}
}
- If order is 1, it is in ascending order, otherwise in descending order.
- If you put the current time in the "stakingTimeFilter", only the currently valid staking list is retrieved.
/// In dart
var stakingTimeFilter = DateTime.now().millisecondsSinceEpoch;
Response:
{
"jsonrpc": "2.0",
"id": "55900",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {
"pageNumber": 1,
"pageSize": 10,
"totalPages": 1,
"totalElements": 1,
"list": [
{
"contractAddress": "0x82fb521a90b8ac242801e4603434968e2cdd9920",
"owner": "0x5f619702528e9de7f5a4a233cd1896902385e705",
"stakingToken": "0x5f748cff221bf63bdadf33cd2678093930e7fb2a",
"rewardToken": "0x3ff720bf49f69a61fd2c9a19a5b9a33ed5a59555",
"rewardRate": 100,
"limitStakingTime": 1666427295713,
"limitRewardTime": 1666427295713,
"txId": "0x81c0ae9709ea292d4546adb991fe13be4d06f3190c35641e9870e9adea493150",
"blockNumber": 3621918,
"txTime": "2022-10-17T17:28:38"
}
]
}
}
}
- "contractAddress" is the address to be used for staking later. Hereafter, we will refer to it as "stakingAddress".
- "stackingToken" and "rewardToken" are the contract addresses. In UI, the token symbol corresponding to the contract address should be shown.
- "limitStakingtime" and "limitRewardTime" are the number of seconds that have elapsed since January 1st, 1970 00:00:00 UTC.
- "rewardRate" is the interest rate per second. The unit is 0.0000000000000000001. If the rewardRate is "10000000000", then 10000000000 * 3600 * 24 * 365 = 3.1536% per year.
First, before staking, you need to approve your tokens to the staking address.
Get a temp key.
{
"jsonrpc": "2.0",
"id": "10029",
"method": "net_getTempKey",
"params": {
"address": "0x5f619702528e9de7f5a4a233cd1896902385e705",
"keyType": "approve"
}
}
- "address" is your address.
- "keyType" should be "approve".
Response:
{
"jsonrpc": "2.0",
"id": "10029",
"result": {
"resultCode": "200",
"resultMessage": "Success",
"resultData": {