All APIs take a callback function as a parameter and execute the callBackFunc after the corresponding method is successfully executed.
The callback function type that takes an optional parameter responseData and returns a Promise object. When the API call returns, the callback function is called with the responseData parameter, which is the data returned from the API call. The callback function can then process the data and handle any errors that occurred during the API call.
connect is used for handling login functionality for nulink web agent. It opens a new window for the user to complete the login process, and then executes the callBackFunc with the login data when the login is successful.
Parameters
Promise : CallBackFunc - A callback function that will be called with the response data from the server.
Returns
{
accountAddress: string - the address of the logged-in user
accountId: string - the ID of the logged-in user
action: 'login' - the action type
result: string
redirectUrl: string
}
Example
import { connect } from"@nulink_network/nulink-web-agent-access-sdk"constgotoConnect=async () => {awaitconnect(loginSuccessHandler)}constloginSuccessHandler:CallBackFunc=async (responseData) => {if (responseData) {// Do something with the responseDataconsole.log(responseData); } else {// Handle the error caseconsole.error('Failed to login in'); }}
apply The apply function is used for applying for files, takes eight parameters: dataCreatorAddress,dataId,dataName,dataStorageUrl, dataHash,zkProof,usageDays and callBackFunc, which is the callback function to be executed after the application is successful.
Parameters
dataName : string - The data name
dataId : string - The data id
dataCreatorAddress : string - The data creator Address
dataUrl : string - The data storage url
dataHash : string - The data hash
zkProof : string - The data zkProof
usageDays : number - The number of days applied
Promise : CallBackFunc - A callback function that will be called with the response data from the server.
The parameters in the apply API can be obtained from the response of the getFileListgetFileDetail
Returns
{
accountAddress: string - the address of the logged-in user
accountId: string - the ID of the logged-in user
action: 'apply'
subAction?: string
owner: string - the file owner's address
user: string - the file requester's address
result: string
redirectUrl: string
}
Example
import { apply } from"@nulink_network/nulink-web-agent-access-sdk"constapplyForFile=async () => {awaitapply(_dataName, _dataId, _dataCreatorAddress, _dataUrl, _dataHash, _zkProof, _usageDays,async () => {if (responseData) {// Do something with the responseDataconsole.log(responseData); } else {// Handle the error caseconsole.error('Failed to upload'); } });};
approveis used for approving files, takes parameters: applyId, applyUserAddress, applyUserId, dataName, dataHash, dataUrl, days, backupNodeNum and callBackFunc.
Parameters
applyId : string - the application ID
applyUserId : string - the application user id
applyUserAddress : string - the application user address
dataName : string - The data name
dataUrl : string - The data storage url
dataHash : string - The data hash
days : string - the application days
backupNodeNum : number - number of nodes used for data backup, this number is the response of getUrsulaNumber API
Promise : CallBackFunc - A callback function that will be called with the response data from the server.
Returns
{
accountAddress: string - the address of the logged-in user
accountId: string - the Id of the logged-in user
action: string
subAction?: string
from: string - the file owner's address
to: string - the file requester's address
applyId: string - the apply id
result: string
redirectUrl: string
}
Example
import { approve } from"@nulink_network/nulink-web-agent-access-sdk"constapproveSubmit=async () => { await approve(_applyId, _applyUserId, _applyUserAddress, _dataName, _dataUrl, _dataHash, _days, _backupNodeNum, async () => {
if (responseData) {// Do something with the responseDataconsole.log(responseData); } else {// Handle the error caseconsole.error('Failed to upload'); } }); };
The dataDownload API provides the function of downloading files.
Parameters
dataId : string - The ID of the data to be downloaded
dataName : string - The name of the data to be downloaded
dataHash : string - The hash of the data to be downloaded
ownerAddress : string - The owner of the data
zkProof : string - The zk proof of the data
dataUrl : string - The data storage url
encryptedDataSize - The size of encrypted data
Promise : CallBackFunc - A callback function that will be called with the response data from the server.
Returns
{
accountAddress: string
accountId: string
fileName: string
action: 'decrypted'
subAction?: string
result: 'success' | 'failed'
redirectUrl: string
arrayBuffer?: string - The ArrayBuffer of the raw data
errorMsg?: any
}
accountId : string - ID of the currently logged-in user
fileName : string - File name, supports fuzzy matching, can be empty.
include : boolean - If include=false, exclude the files belonging to the current account; otherwise, the files belonging to the current user will be placed at the beginning of the list.
format : string - the format of file,can be empty.
desc : boolean - Whether to sort in descending order by upload time
pageNum : number - page number (starting from 1)
pageSize : number - page size
Returns
{ total: number list: [{ file_id: string - the file ID file_name: string - the file name file_hash: string - the file hash file_raw_size: string - the original file size file_zk_proof: string - the zero-knowledge proof of file file_encrypted_size: string - The size of the encrypted file category: string - the file category/type format: string - file format suffix: string - file suffix address: string - file address thumbnail: string - file thumbnail owner: string - file owner file_url: string - file storage url address: string - the file hash in backend owner_id: string - file owner's account ID owner_avatar: string - file owner's avatar created_at: number - file upload timestamp }]}
Promise: CallBackFunc - A callback function that will be called with the response data from the server.
toAddress: string - The recevier of the transaction.
rawTxData?: string - The call data of the transaction, can be empty for simple value transfers.
value?: string - The value of the transaction in wei.
gasPrice?: string - The gas price (wei) set by this transaction, if empty, it will use web3.eth.getGasPrice()
Returns
{
accountAddress: string - the address of the logged-in user
accountId: string - the Id of the logged-in user
toAddress: string - The receiving address
rawTxData?: string - The call data of the transaction
value?: string - The value of the transaction in wei
gasPrice?: string - The gas price (wei) set by this transaction
action: string - "transaction"
subAction?: string
result: string - 'success' or 'filed'
transactionHash?: string - the transaction hash, if success
errorMsg?: any - the error message
}