Skip to main content

3.0 SDK's Return Result Format

{
"code": 0,
"msg": "success",
"count": 0,
"data": {}
}

The main parameters returned include:

Variable NameTypeDescription
codeintRequest return result, 0 for success, other values for failure
msgstringError message, success for success, other values for failure
countintWhen data is a JSON array, count represents the number of elements in data
dataobjectSpecific returned data, data can be a single JSON object or a JSON object array

3.1 Querying Supported Chain Information

Querying Supported Chain Information

HashNut supports multiple chains and currencies. Before merchants create orders, they can first query the chains supported by HashNut, and then query the currencies supported by that chain through the chain's code.

curl --location --request POST 'https://testnet-web3.hashnut.io/api/v2.0.0/config/queryAllChainInfo'

The returned information is as follows:

{
"code": 0,
"msg": "success",
"ui": null,
"version": null,
"count": 0,
"data": [
{
"id": 1,
"chain": "ETH",
"chainDesc": "BlockChain Ethereum",
"enable": true,
"receiptAddress": "0x8126ac362f08ec6a58b43e537f3dbbb474c70595",
"txConfirmCount": "3",
"walletConnectEnable": true,
"bridgeServerAddress": "https://bridge.hashnut.io",
"decimals": 18,
"baseChainSymbol": "Ethereum",
"env": 1,
"chainId": "11155111",
"baseChainCoin": "ETH",
"createTime": 1710938845128,
"updateTime": 1710938845128,
"eip712ChainId": "0",
"eip1559Support": true
}
...
]
}

The main parameters returned include:

Variable NameTypeDescription
chainstringAbbreviation of the name of the public chain supported by Hashnut, for example: ETH, BSC, TRON, POLYGON, etc.
chainDescstringDescription of the public chain
enablebooleanWhether the public chain is available
receiptAddressstringThe receiving address of HashNut platform on the public chain
txConfirmCountintThe number of confirmations required for transactions on the public chain. If the confirmation count is reached or exceeded, Hashnut considers the transaction of the payment order valid
walletConnectEnablebooleanWhether the public chain supports walletconnect protocol for payment. If the walletconnect protocol is not supported, end users need to scan the payment QR code with a wallet app
bridgeServerAddressstringBridge server address for walletconnect
decimalsintFor example: the precision of ETH is 18 decimal places, and the precision of TRON is 6 decimal places
baseChainSymbolstringThe name of the base chain
envintThe environment of the current payment platform 0-Production 1-Testing 2-Development
chainIdlongChainID of the EVM compatible chain, for example: 137 for the mainnet of POLYGON, 80001 for the Mumbai testnet
baseChainCoinintAbbreviation of the base chain's currency, for example: ETH for Ethereum, MATIC for the base currency on POLYGON
eip712ChainIdstringThe chainId of this chain in eip712, this value is only valid for public chains that support eip712
eip1559SupportintWhether eip1559 is supported

3.2 Query supported chain and currency information

Query supported chain and currency information

After obtaining the chain code, obtain the currencies supported by that chain, for example: query supported erc20 currencies

curl --location --request POST 'https://testnet-web3.hashnut.io/api/v2.0.0/config/queryAllCoinInfo'

The returned information is as follows:

{
"code": 0,
"msg": "success",
"ui": null,
"version": null,
"count": 0,
"data": [
{
"id": 1,
"chain": "ETH",
"chainCode": "erc20",
"coinCode": "usdt",
"isToken": true,
"enable": true,
"contractAddress": "0xe2d7250b2ec3cd208ac5b42886edd162411529c4",
"coinDesc": "tether usdt",
"gateWayEnable": true,
"decimals": "6",
"createTime": 1710938845130,
"updateTime": 1710938845130,
"nftmarket": "opensea"
}
...
]
}

The main return parameters are as follows:

Variable NameTypeDescription
chainstringThe name of the chain where the currency is located, for example: ETH
chainCodestringThe code of the chain supported by hashnut, currently hashnut supports erc20, trc20, bep20, polygon-erc20
coinCodestringCurrency code, currently erc20 supports usdt, usdc, bep20 supports busd, hashnut, trc20 supports usdt
isTokenbooleanWhether the currency is a token, if it is the basic token of a public chain, such as eth, bsc, trx, then this value is false
enablebooleanWhether the currency is currently available on hashnut, if the currency is not available, then orders cannot be created
contractAddressstringThe smart contract address of the current currency on this public chain
coinDescstringDescription information of the currency
gateWayEnablebooleanIf this field is true, users can make gateway payments through the Binance app or other apps. Currently, Hashnut only supports Binance gateway
decimalsintThe precision of the currency, for example, the precision of the USDT currency in erc20 is 6, so when paying 1 USDT, the amount needs to be filled in as 1000000. For example, the precision of BUSD is 18

3.3 Querying supported currency information by currency type

Querying supported currency information by currency type

curl --location 'https://testnet-web3.hashnut.io/api/v2.0.0/config/querySupportCoinsByChainCode' \
--header 'Content-Type: application/json' \
--data '{
"chainCode":"erc20"
}'

The returned information is as follows:

{
"code": 0,
"msg": "success",
"ui": null,
"version": null,
"count": 0,
"data": [
{
"id": 2,
"chain": "ETH",
"chainCode": "erc20",
"coinCode": "usdc",
"isToken": true,
"enable": true,
"contractAddress": "0x4ca772bb3e6326647b8dd02ddbc758773aa7c650",
"coinDesc": "usdc",
"gateWayEnable": true,
"decimals": "6",
"createTime": 1710938845132,
"updateTime": 1710938845132,
"nftmarket": "opensea"
},
...
]
}

Parameters carried in the request body:

Variable NameTypeDescription
chainCodestringtoken type, currently supported by HashNut: erc20, trc20, bep20, polygon-erc20

The main return parameters are as follows:

Variable NameTypeDescription
chainstringThe name of the chain where the currency is located, for example: ETH
chainCodestringThe code of the chain supported by hashnut, currently hashnut supports erc20, trc20, bep20, polygon-erc20
coinCodestringCurrency code, currently erc20 supports usdt, usdc, bep20 supports busd, hashnut, trc20 supports usdt
isTokenbooleanWhether the currency is a token, if it is the basic token of a public chain, such as eth, bsc, trx, then this value is false
enablebooleanWhether the currency is currently available on hashnut, if the currency is not available, then orders cannot be created
contractAddressstringThe smart contract address of the current currency on this public chain
coinDescstringDescription information of the currency
gateWayEnablebooleanIf this field is true, users can make gateway payments through the Binance app or other apps. Currently, Hashnut only supports Binance gateway
decimalsintThe precision of the currency, for example, the precision of the USDT currency in erc20 is 6, so when paying 1 USDT, the amount needs to be filled in as 1000000. For example, the precision of BUSD is 18

3.5 Create Order

Create Order

HashNut supports multi-currency payments, merchants can create orders and choose payment channels for orders

Request:

curl --location 'https://testnet-web3.hashnut.io/api/v2.0.0/pay/createPayOrderWithApiKey' \
--header 'hashnut-request-uuid: xxxx' \
--header 'hashnut-request-timestamp: xxxx' \
--header 'hashnut-request-sign: xxxx' \
--header 'Content-Type: application/json' \
--data '{
"accessKeyId": "ACC_1156690317534035968",
"merchantOrderId": "100000",
"chainCode": "polygon-erc20",
"coinCode": "usdt",
"amount": 1.13,
"receiptAddress": "0x1a580cca96a3d1070cb23b63480b3afafe0bf025"
}'

Parameters carried in the request body:

Variable NameTypeDescription
accessKeyIdstringMerchant API KEY ID
merchantOrderIdstringMerchant order number, a unique order ID generated by the merchant
chainCodestringChain code
coinCodestringCurrency code
amountDecimal(20)Amount to be paid, accurate to a maximum of 2 decimal places
receiptAddressstringAddress of the smart contract deployed by the merchant

Parameters carried in the request header:

Variable NameTypeDescription
hashnut-request-uuidstringUUID generate by merchant
hashnut-request-timestampstringtimestamp
hashnut-request-signstringSign (uuid+timestamp+body) with the API secret key, where the body is the JSON-serialized string of the request content.

The code for generating hashnut-request-sign is as follows:

    String uuid=request.getHeader("hashnut-webhook-uuid");
String timeStamp=request.getHeader("hashnut-webhook-timestamp");
// body is body is the JSON-serialized string of the request content
String dataToSign=String.format("%s%s%s",uuid,timeStamp,body);
String sign= PayDigestUtil.HMACSHA256Base64(HashNutConfig.secretKey,dataToSign);

the PayDigestUtil.HMACSHA256Base64 code:

    public static String HMACSHA256Base64(String key,String data) throws Exception {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
sha256_HMAC.init(secret_key);
sha256_HMAC.update(data.getBytes());
byte[] array = sha256_HMAC.doFinal();
return Base64.getEncoder().encodeToString(array);
}

The returned information is as follows:

{
"code": 0,
"msg": "success",
"ui": null,
"version": null,
"count": 0,
"data": {
"mchAddress": "0x6a0b7b0b95ce640b3fe3fede6ebfed4de9293019",
"chain": "POLYGON",
"chainCode": "polygon-erc20",
"coinCode": "usdt",
"createChannel": 1,
"accessChannel": 0,
"merchantOrderId": "10000",
"payOrderId": "01HSKATBCK7CE20N88B25870M5",
"tokenAddress": "0x0de51eb069fd04f5ff6fb48f1dad6766ac558b33",
"receiptAddress": "0x78f43ee9985aacd8da1c6dd099213b402aa98672",
"amount": 1.160000,
"state": 4,
"accessSign": "24625267842A4074D6332A59A7BE49069C63B0392340171F1E2F1FF8C6AA9879",
"payTxId": "0xd77cd2e8488e3b8db02dc5e3f2bdac2da99795fbcf91408b6eae68da50d752fb",
"confirmCount": "3",
"walletConnectEnable": true,
"bridgeServerAddress": "https://bridge.hashnut.io",
"eip712ChainId": "0",
"chainId": "80001",
"createTime": "0",
"rate": 80,
"obtainAmount": 1.15072,
"platformFee": 0.00928
}
}

The parameters in the response include

Variable NameTypeDescription
chainstringChain where the payment order token is located
mchAddressstringMerchant address for placing orders, which is the merchant address that created the payment smart contract
chainCodestringChain code
coinCodestringCurrency code
createChannelintChannel through which the merchant created the order, 0-Merchant system 1-ApiKey, since the order is created through the API key, the value is 1
accessChannelbyteThe channel through which the end user pays for the order, since it is a blockchain payment, the value is 0
merchantOrderIdstringMerchant order number, a unique order ID generated by the merchant
payOrderIdstringHashnut's platform order number, a unique receiving address generated by Hashnut
contractAddressstringThe smart contract address of the currency, when users send transactions, 'to' needs to be filled with the smart contract address of the currency
receiptAddressstringSmart contract address used to receive user funds
inputDatastringInput data of the transaction, encoded using web3j, including: Hashnut receiving address and order amount
accessSignstringSignature of (platformId+mchOrderId) using the API key

Merchant concatenates the payment order URL

Merchants use the accessSign, merchantOrderId, and payOrderId from the create order response to concatenate a payment URL to send to the end user, for example:

https://testnet-web3.hashnut.io/pay?accessSign=42889E72DAAE0C4275F804DDDFA4707823FE30EB4D4BB6064859CB65AA3E6305&merchantOrderId=10000&payOrderId=01HSKATBCK7CE20N88B25870M5

The parameters in the URL are:

Variable NameTypeDescription
accessSignstringSignature of (platformId+merchantOrderId) using the api key
merchantOrderIdstringMerchant order ID
payOrderIdstringHashNut platform order ID, a unique order ID generated by HashNut

3.6 Callback notification

Callback notification

The callback URL can be configured in the Create ApiKey interface, including backend callback URL and frontend callback URL, both of which contain the following parameters:

Variable NameTypeDescription
payOrderIdstringHashNut platform order ID, a unique order ID generated by HashNut

3.7 Query order

Query order information

After receiving the payment order URL, users need to use accessSign to query the order information first to confirm if the order has been paid to prevent duplicate payments

Request:

curl --location 'https://testnet-web3.hashnut.io/api/v2.0.0/pay/queryPayOrderWithAccessSign' \
--header 'Content-Type: application/json' \
--data '{
"merchantOrderId": "a89206d0-7883-48dd-9316-e494f2679e72",
"payOrderId": "01HSKATBCK7CE20N88B25870M5",
"accessSign": "24625267842A4074D6332A59A7BE49069C63B0392340171F1E2F1FF8C6AA9879"
}'

The requested parameters include:

Variable NameTypeDescription
merchantOrderIdstringMerchant order number, a unique order ID generated by the merchant
payOrderIdstringPlatform order number of hashnut
accessSignstringSignature of (platformId+mchOrderId) using the API key

The returned information is as follows:

{
"code": 0,
"msg": "success",
"ui": null,
"version": null,
"count": 0,
"data": {
"mchAddress": "0x6a0b7b0b95ce640b3fe3fede6ebfed4de9293019",
"chain": "POLYGON",
"chainCode": "polygon-erc20",
"coinCode": "usdt",
"createChannel": 1,
"accessChannel": 0,
"merchantOrderId": "a89206d0-7883-48dd-9316-e494f2679e72",
"payOrderId": "01HSKATBCK7CE20N88B25870M5",
"tokenAddress": "0x0de51eb069fd04f5ff6fb48f1dad6766ac558b33",
"receiptAddress": "0x78f43ee9985aacd8da1c6dd099213b402aa98672",
"amount": 1.160000,
"state": 4,
"accessSign": "24625267842A4074D6332A59A7BE49069C63B0392340171F1E2F1FF8C6AA9879",
"payTxId": "0xd77cd2e8488e3b8db02dc5e3f2bdac2da99795fbcf91408b6eae68da50d752fb",
"confirmCount": "3",
"walletConnectEnable": true,
"bridgeServerAddress": "https://bridge.hashnut.io",
"eip712ChainId": "0",
"chainId": "80001",
"callBackUrl": "https://testnet-web3.hashnut.io/shop/payFinish?payOrderId=01HSKATBCK7CE20N88B25870M5&chain=POLYGON&amount=1160000&chainCode=polygon-erc20&sign=CAD9387C2D51389B2512C324932B1277F68B177E6C3933BC5EA686FB3A935C8C&merchantOrderId=a89206d0-7883-48dd-9316-e494f2679e72&accessSign=24625267842A4074D6332A59A7BE49069C63B0392340171F1E2F1FF8C6AA9879&obtainAmount=1150720&payTxId=0xd77cd2e8488e3b8db02dc5e3f2bdac2da99795fbcf91408b6eae68da50d752fb&receiptAddress=0x78f43ee9985aacd8da1c6dd099213b402aa98672&merchantAddress=0x6a0b7b0b95ce640b3fe3fede6ebfed4de9293019&confirmCount=3&state=4&coinCode=usdt&paySuccessTime=",
"createTime": "0",
"rate": 80,
"obtainAmount": 1.150720,
"platformFee": 0.009280
}
}

The response parameters include:

Variable NameTypeDescription
chainstringChain where the payment order token is located
mchAddressstringMerchant address for placing orders, which is the merchant address that created the receiving smart contract
chainCodestringChain code
coinCodestringCurrency code
createChannelintChannel through which the merchant created the order, 0-merchant system 1-ApiKey, as the order was created through an API key, the value is 1
accessChannelbyteChannel through which the end user pays the order, as it is a gateway payment, the value is 1
mchOrderIdstringMerchant order number, a unique order ID generated by the merchant
platformIdstringPlatform order number of hashnut, a unique order number generated by hashnut
contractAddressstringThe smart contract address of the currency, users need to fill in 'to' with the smart contract address of the currency when sending transactions
receiptAddressstringThe smart contract address that receives user funds
inputDatastringThe input data of the transaction, encoded using web3j, including: hashnut receiving address and order amount
accessSignstringSignature of (platformId+mchOrderId) using the api key
qrcodeLinkstringGateway payment QR code image address
qrContentstringThis value is ignored
walletConnectEnablebooleanWhether this order supports walletconnect launch
bridgeServerAddressstringIf walletConnectEnable is true, this value represents the walletconnect bridge server address

When replying to the user, the user needs to pay attention to the state of the order. If the state is greater than 0, it means that the payment has already been made, and further payment will be rejected

For a more concise and detailed usage method, please refer to Test Case Source Code In ServiceTest.java