Dapp SDK Guide

1. DAPP Default API

Dapp Default API can be accessed via HTTP request in frontend

1.1 Login

API: /api/dapps/dappID/login HTTP Method: Post

Request Parameter:

Name Type Description
secret string NASGO account's Secret

Return Parameter:

Name Type Description
success boolean
account json All information related to one account : balance, address,publickey

1.2 Invoke contract

API:/api/dapps/dappID/transactions/unsigned

Request Parameter:

Name Type Description
secret string NASGO account's Secret
fee string specify the fee
type integer contract's ID registered in init.js
args string JSON.stringify(args array)

Return Parameter:

Name Type Description
success boolean
error string defined in your contract

1.3 Contract List

API:/api/dapps/dappID/contracts

Request Parameter: none

Return Parameter:

Name Type Description
contracts array all contracts related to an Dapp

2.DAPP SDK

DApp SDK API can be invoked in contact

1.1 DB

app.sdb.get(model, conditon)

Request Parameter:

Name Type Description
model string model name
cond string specify the fee

Return:

Type Description
object an object contains the data matched the query conditions

app.sdb.keys(model)

Request Parameter:

Name Type Description
model string model name

Return:

Type Description
array all indexed fields of a model

app.sdb.entries(model)

Request Parameter:

Name Type Description
model string model name

Return:

Type Description
array all cached fields of a model

app.sdb.create(model, values)

Parameter:

Name Type Description
model string model name
values object Data items that will be created

Return: none

app.sdb.replace(model, rows)

Request Parameter:

Name Type Description
model string table name
values string Data items that will be created or updated

Return:none

app.sdb.update(model, item, condition)

Request Parameter:

Name Type Description
model string table name
item object item will be updated
condition object the contition for DML

Return:

3.Balance

app.balances.get(address, currency)

Parameter:

Name Type Description
address string nasgo address
currency string token's symbol

Return:

Type Description
address nasgo address
currency token's symbol
balance account's balance

app.balances.increase(address, currency, amount)

Parameter:

Name Type Description
address string nasgo address
currency string token's symbol
amount bigint amount to increase

Return:none

app.balances.decrease(address, currency, amount)

Parameter:

Name Type Description
address string nasgo address
currency string token's symbol
amount bigint amount to decrease

Return:none

app.balances.transfer(currency, amount, from, to)

Parameter:

Name Type Description
currency string token's symbol
amount bigint amount to increase
from string sender's address
to string recipient's address

Return:none

4.Router

app.route.get(path, handler)

app.route.get('/getBalance/:address',  async function (req) {
  return;
})

api : /dapps/dappID/getBalance/addressParam

type: GET

app.route.post(path, handler)

app.route.post('/getBalance',  async function (req) {
  return;
})

api : /dapps/dappID/getBalance

type: POST

app.route.put(path, handler)

app.route.put('/getBalance',  async function (req) {
  return;
})

api : /dapps/dappID/getBalance

type: PUT

5.Register contract and Fee

app.registerContract(id, path)

Parameter:

Name Type Description
id string contract ID
path string path of contract
app.registerContract(1000, 'mycontract.deductBalance')

contract can be invoked only if it is declared in init.js

app.registerFee(type, fee, currency)

Parameter:

Name Type Description
id string contract ID
fee string cost when a contract is invoked
currency string currency
app.registerFee(1000, '1000000', 'NSG')

app.setDefaultFee(fee, currency)

Set fee for all contracts in the system.

Parameter:

Name Type Description
fee string cost when a contract is invoked
currency string currency
app.setDefaultFee('1000000', 'NSG')

results matching ""

    No results matching ""