Spartan NTT Management Contract
Function Introduction
The NTT management contract provides a complete set of NTT APIs for the data center’s NTT wallet management. The APIs include NTT generation, NTT transfer, NTT query and other functions.
The transaction types are as follows:
0 | Node Establishment Incentive Program |
1 | Monthly Incentive |
3 | Top Up Gas Credit |
4 | Top Up NTT |
7 | NTT refund |
8 | NTT collection |
10 | Emergency Gas Credit Top-Up Service Fee |
Smart contract address: 0x503Aa847AcBCF89EC8F05557436871c7A8662070
API Definition
Mint NTT Data
The Data Center Operator can get NTT mint data by parsing this event.
Event parameters: operator, sender address (0x0), receiver address, amount of NTT, the balance of sender address (null), the balance of receiver address, transaction type;
Event definition: Transfer (address indexed operator, address indexed from, address to, uint256 amount, uint256 fromBalance, uint256 toBalance, TransType transType);
Example:
public ReqJsonWithOfflineHashBean transfer(String sender, String from, String to, BigInteger amount, int transType, RequestOptions options) throws Exception {
// check sender
checkSender(sender);
// check from
checkAddress(from, "from account");
// check to
checkAddress(to, "to account");
// check amount
checkBigIntegerEmpty(amount, "amount");
// input params
ArrayList<Object> arrayList = new ArrayList<>();
arrayList.add(from);
arrayList.add(to);
arrayList.add(amount);
arrayList.add(transType);
// build transaction
ReqJsonRpcBean reqJsonRpcBean = assembleTransaction(sender, NTTFunctions.TRANSFER, arrayList, options, nttContract);
String offLineHash = Hash.sha3(reqJsonRpcBean.getParams().get(0).toString());
ReqJsonWithOfflineHashBean reqJsonWithOfflineHashBean = new ReqJsonWithOfflineHashBean();
reqJsonWithOfflineHashBean.setOffLineHash(offLineHash);
reqJsonWithOfflineHashBean.setReqJsonRpcBean(reqJsonRpcBean);
return reqJsonWithOfflineHashBean;
}
Transferred NTT Data
The Data Center Operator can get transferred NTT data by parsing this event.
Event parameters: operator, sender address, receiver address, amount of NTT, balance of sender address, balance of receiver address, transaction type;
Event definition: Transfer (address indexed operator, address indexed from, address to, uint256 amount, uint256 fromBalance, uint256 toBalance, TransType transType);
Example:
public ReqJsonWithOfflineHashBean transfer(String sender, String from, String to, BigInteger amount, int transType, RequestOptions options) throws Exception {
// check sender
checkSender(sender);
// check from
checkAddress(from, "from account");
// check to
checkAddress(to, "to account");
// check amount
checkBigIntegerEmpty(amount, "amount");
// input params
ArrayList<Object> arrayList = new ArrayList<>();
arrayList.add(from);
arrayList.add(to);
arrayList.add(amount);
arrayList.add(transType);
// build transaction
ReqJsonRpcBean reqJsonRpcBean = assembleTransaction(sender, NTTFunctions.TRANSFER, arrayList, options, nttContract);
String offLineHash = Hash.sha3(reqJsonRpcBean.getParams().get(0).toString());
ReqJsonWithOfflineHashBean reqJsonWithOfflineHashBean = new ReqJsonWithOfflineHashBean();
reqJsonWithOfflineHashBean.setOffLineHash(offLineHash);
reqJsonWithOfflineHashBean.setReqJsonRpcBean(reqJsonRpcBean);
return reqJsonWithOfflineHashBean;
}
Query NTT Balance
The Data Center Operator can call this interface to query the NTT balance of the NTT wallet.
Input parameters: none;
Output parameters: none;
Function definition: balanceOf (address account) view returns (uint256);
Example:
public BigDecimal balanceOf(String account, RequestOptions options) throws Exception {
// check account address
checkAddress(account, "account address");
// input params
ArrayList<Object> arrayList = new ArrayList<>();
arrayList.add(account);
// send call tran and decode output
InputAndOutputResult inputAndOutputResult = sendCallTransactionAndDecodeOutput(options, arrayList, NTTFunctions.BALANCE_OF, nttContract);
BigInteger amtInteger = ((BigInteger) inputAndOutputResult.getResult().get(0).getData());
BigDecimal bigDecimal = new BigDecimal(amtInteger);
return (bigDecimal.divide(NTT_RATIO));