Skip to main content

API

Network

Currently, there are 3 networks compatible with dio-wallet :

DecimalNetwork
1dioxide main chain network
2dioxide test chain network
3dioxide development chain network

RPC

dioxide.request (args:RequestArguments)

Use the request function to submit an RPC request to the wallet and obtain an asynchronous response.

interface RequestArguments {
method: string;
params?: unknown[] | {[key: string]: any};
}
dioxide.request(args: RequestArguments): Promise<unknown>;

The ProviderRpcError will be returned when an RPC call encounters an exception. Please utilize it to retrieve error details.

dioxide.request({
method: "...",
params: {...},
})
.then(response => {
// The result varies by RPC method.
return response
})
.catch(ex => console.error("ProviderRpcError error",ex))

WalletConnect

WalletConnect is an open-source protocol for connecting DApps to wallets. When invoking this API, it prompts the appearance of a popup window in the wallet, you are required to finish the connection manually within the wallet.

method:

methodparamsmandatoryresponse
request_connect_addressparamsoptionalstring[]

params

nametypemandatorydescription
symbolstringYesonly symbol of DApp

Params are optional when the current DApp is an official Dioxide DApp, such as CoreDApp and Testnet Gadgets.

However, if you're an unofficial DApp connecting to the wallet, you must include params.symbol. Dio-wallet will validate the DApp's authenticity on the chain based on the provided symbol.

When Dio-Wallet is in the developer mode, we don't verify the validity of params.symbol. Check here to open developer mode in Dio-Wallet.

Sample:

dioxide.request({
method: "request_connect_address",
// optional
params: {
symbol: "your_dapp_symbol"
}
})
// complete address connection
.then((accounts: string[]) => {
return accounts[0]
})
// cancel address connection(eg: close the connection window)
.catch (ex: ProviderRpcError => {
console.error(ex.code, ex.message, ex.data)
})

Get the wallet address in use within the DApp

When successfully connected to the DApp, a wallet address will be returned. Otherwise, an empty array will be returned.

nameparamresponse
connected_address-string[]

Sample:

const accounts: string[] = await dioxide.request({
method: "connected_address",
})
console.log(accounts[0])

Get the blockchain network the DApp is connected to

nameparamresponse
network-NetworkItem

Sample:

interface NetworkItem {
name: string;
id: number
}

const network: NetworkItem = await dioxide.request({
method: "network",
})

console.log(network.id, network.name)

Get the balance of the address in use

Please ensure the address is in use in the DApp. Otherwise, calling this API will result in an Unauthorized (code: 4100) error.

nameparamresponse
balance-string

The decimal precision of DIO is 8. The precision of results obtained through RPC requires manual processing. For instance, "100000000:DIO" represents 1 DIO. We recommend using a library like bignumber.js for accurate floating-point conversion or high-precision calculations when working with balances.

Sample:

const balance:string = await dioxide.request({
method: "balance",
})

console.log(balance) // output xxxx:DIO

Get the profile details of the address in use (profile)

nameparamresponse
profile-Profile
interface Profile {
address: string
avatar: string
alias: string
}
const profile: Profile = await dioxide.request({
method: "profile",
})

console.log(profile)

Get the lock screen status of the current wallet

nameparamresponse
is_locked-true(locked) / false(unlocked)

Sample:

const locked: boolean = await dioxide.request({
method: "is_locked",
})
console.log(locked) // output: true or false

Sign and send transactions

nameparammandatoryresponse
send_transactionparamsYstring

params

nametypemandatorydescription
funcstringYcontract function name
argsjsonNcontract parameter. The specific value varies with the function
limitArgsstring[]Ncustom args limit show
tokens<{symbole:amount}>[]Nfca tokens
ttlstringNtime to live
delegateestringNproxy address

DApp built-in wallet sending DIO

params.args:

nametypemandatorydescription
AmountstringYtransfer amount(1 is 1DIO)
TostringYtarget address (receiver)
try {
const txHash: string = await dioxide.request({
method: 'send_transaction',
params: {
func: 'core.coin.transfer',
args: {
Amount:100, // transfer 100 DIO
To:'was7fdnfrqh42c7f68pv9s8efmf8y0hv4y6m3h0sgj3ypdfyv09379wh2g:ed25519'
},
}
})
}
catch(ex) {
if (ex.code === 4001) {
console.error("User Reject")
return
}
console.error("unexpected error:",ex)
}

Create a token

To create a token, access ‘Tokens' in Core Dapps to facilitate this process.

You can also create a token using the API by configuring the parameters below to define the token's characteristics:

params.args:

nametypemandatorydescription
SymbolstringYToken name(3-8 capital letters - #)
FlagsuintY"1" represents an immutable minter, "0" represents a mutable minter
InitSupplyuintYInitial quantity (default to 0 during creation)
MinteruintYThe cid (contractid) for the token contract can be initialized with a value of 1.
DepositstringYpre-deposited DIO during initialization (the precision of DIO must be included. If the precision of DIO decimal is 8 digits, the pre stored 1 DIO must be represented as 100000000)
DecimalsuintYToken precision

For example:

const txHash: string = await dioxide.request({
method: 'send_transaction',
params: {
func: 'core.delegation.create_token',
args:{
"Flags":1,
"Minter": 1,
// pre store 2345 DIO,expression is String(2345 * 10**8)
"Deposit":"234500000000",
// 5-digit decimal precision,Initial circulation is 100, Initial expression is String(100 * 10**5)
"InitSupply": 0,
"Symbol":"TOKEN1"
"Decimals": 8
},
}
})

Set Token/DApp metadata information

Access Core DApps to configure the metadata information.

params.delegatee:

nametypemandatorydescription
delegateestringYThe address of the Token/NFT/DApp for which metadata will be configured

params.args:

nametypemandatorydescription
MetadatastringYmetadata information.
const txHash: string = await dioxide.request({
method: 'send_transaction',
params: {
func: 'core.profile.set_metadata',
args: {"Metadata":"{\\"IconUrl\\":\\"https://png.pngtree.com/png-clipart/20220921/ourmid/pngtree-halloween-gnome-pumpkin-bat-illustration-png-image_6209020.png\\",\\"Description\\":\\"The description of token1\\",\\"Social\\":{}}"},
//The token address to be edited is c0jkjfzyzebdgyt2zcdp7125h8hpmvkv3rbwcsvkh0eea75jy00fkz02dr:token"
delegatee: "TOKEN1:token"
},
})

Faucet

const txHash: string = await dioxide.request({
method: 'send_transaction',
params: {
func: 'core.coin.faucet',
}
})

Create a DApp

To create a token, access ‘DApps' to facilitate this process.

You can also create a DApp using the API by configuring the parameters below to define the DApp's characteristics:

params.args:

nametypemandatorydescription
NamestringYDApp name,4-8 alphanumeric digits and _-#@
TypeuintYMust be 10,meaning creating a DApp
DepositstringYThe amount of token deposited to the DApp, no less than 10000000
const txHash: string = await dioxide.request({
method: 'send_transaction',
params: {
func: 'core.delegation.create',
args: {
"Name":"MYDAPP",
"Type": 10,
// 32 DIO
'Deposit': "3200000000"
},
},
})

Increase token supply

params.args:

nametypemandatorydescription
amountstringYThe amount of the increased token supply, including the decimal precision of token (For example, with a decimal precision of 5, issuing an additional 1 token means 100,000)
token_idstringYThe Contract ID of the token contract
const txHash: string = await dioxide.request({
method: 'send_transaction',
params: {
func: 'Asset.TokenManager.mint',
// If Symbol is ATH and decimal precision is 5, then 3 ATH will be issued additionally, which is expressed as Amount: 3 * 10 * * 5
args: {
"amount":"300000",
"token_id": "token_id"
}
})

Transfer DIO between any addresses

params.delegatee:

nametypemandatorydescription
delegateestringIf the address belongs to a Token/DApp, this parameter is required; otherwise, it is optionalDIO target address

params.args:

nametypemandatorydescription
TostringYThe recipient’s address
AmountstringYTransfer amount of DIO(1 is 1 DIO)
const hash: string = await dioxide.request({
method: "send_transaction",
params: {
func: "core.coin.transfer",
args: {
// It can be any chain address such as token/app/user
To: "c0jkjfzyzebdgyt2zcdp7125h8hpmvkv3rbwcsvkh0eea75jy00fkz02dr:token",
// transfer 200 DIO
Amount: '200'
},
// If the target address is Token/DApp, delegatee is a required parameter and the value is the current address to be transferred out
// the connection address of the current wallet must have the management permission of the current address to be transferred out
delegatee:TOKEN:token”,
},
});
console.log("tranasction hash", hash);

Get Estimated Transfer Gasfee

params

nametypemandatorydescription
funcstringYcontract function name
argsjsonNcontract parameter. The specific value varies with the function
const gasFee = await dioxide.request({
method: 'gasfee',
params: {
func: 'core.coin.transfer',
args: {
Amount: 150,
To: 'm04adrp625hw66pg98xtzcwvyth7qd39rst7k96crcj5phmte7b26jj7bc:ed25519'
},
}
})
console.log("tranasction gasFee", gasFee);

Event

JS-API provides a set of built-in event processes, from which you can monitor if the address in use changes.

connected_address_changed

The address in use has changed, triggered by the event of switching the active address in

Dio-wallet.

dioxide.on('connected_address_changed', (accounts: string[]) => {
// Handle the new accounts, or lack thereof.
// "accounts" will always be an array,
});

network_changed

The blockchain network the DApp is connected to has changed. For example, switching the test network to the development network or the main network in Dio-wallet.

interface NetworkItem {
name: string;
id: number
}

dioxide.on('network_changed', (chain: ChainItem) => {
// Handle the new chain.
// Correctly handling chain changes can be complicated.
// We recommend reloading the page
// unless you have good reason not to.
window.location.reload();
});

disconnect

DApp is disconnected from the Network. For example, lost connection between wallet and remote service.

dioxide.on('disconnect', handler: (error: ProviderRpcError) => void);

lock_status_changed

The status of Lock screen has changed. For example, the wallet locks the screen.

dioxide.on("lock_status_changed", (locked: boolean) => {});

Errors

The error messages returned by an RPC request:

interface ProviderRpcError extends Error {
message: string;
code: number;
data?: unknown;
}

for example:

dioxide.request({
method: "request_connect_address",
params: {
logo: "https://scan.dioxide.network/img/logo.png",
},
})
.then((accounts: string[]) => {
return accounts
})
.catch (ex: ProviderRpcError => {
console.error(ex.code, ex.message, ex.data)
})

part of build-in error code:

export enum StandardCode {
UserReject = 4001,
Unauthorized = 4100,
Unsupported_Method = 4200,
Unsupported_Event = 4300,
Absent_method_handler = 4400,

Disconnected = 4900, // The Provider is disconnected from all chains.
Chain_Disconnected = 4901, // The Provider is not connected to the requested chain.

Invalid_Request = 32600,
Method_Not_Found = 32601,
Invalid_Params = 32602,
Internal_Error = 32603,
Dioxide_Scan_Service_Error = 32604,
Operation_Timeout = 32605,
Parse_Error = 32700,
}

const StandardMessage: KeyValue<string> = {
4001: 'User Reject',
4100: 'unauthorized',
4200: 'unsupported method',
4300: 'unsupported event',
4400: 'absent method handler',

4900: 'all chains disconnected',
4901: 'the chain disconnected',

32600: 'invalid request',
32601: 'method not found',
32602: 'invalid params',
32603: 'internal error',
32604: 'dioxide scan service networking error',
32605: 'operation timeout',
32700: 'parse error',
}