Skip to main content

WalletConnect

Connecting a wallet acts as a gateway that allows users to interact with the blockchain through the DApp, using their wallet address as an authorized identity. DApps can only call the OpenAPI of the wallet after connecting to the wallet, otherwise some APIs will be restricted.

There are two connection (authorization) modes:

  1. Connecting to the entire wallet, meaning all addresses of dio-wallet are connected to the DApp.
  • All addresses are authorized for use within the DApp.
  • The address in use in the DApp is synchronized with the one connected in the wallet. If the user switches addresses in their wallet, the DApp active address changes accordingly.
  • connected_address_changed is triggered if the user switches addresses in their wallet.
  • When the DApp calls wallet_API, it utilizes the information associated with the currently active address in the DApp, typically for functions such as signing transactions.

2. Single Address Connection (or Authorization) Mode

  • Only the selected wallet and address are authorized for use within the DApp.
  • If the user switches addresses in their wallet, the DApp active address does not change.
  • Hence, switching addresses in the user’s wallet does not trigger the connected_address_changed event;
  • When the DApp calls the wallet API, it utilizes the information associated with the currently active address in the DApp, regardless of the user’s active address in wallet.

Sample

detectProvider().then((dioxide) => {
if (dioxide) {
startApp(dioxide);
} else {
console.log('Please install Dioxide wallet!');
}
})
function startApp(diox) {
const button = document.querySelector("conenct_btn")
button.addEventListener("click", async () => {
try {
const connectedAddr = await diox.request({
method: "request\_connect\_address",
params: {
symbol: "YOUR\_DAPP\_SYMBOL",
},
});
console.log("DApp has been connected diox-wallet")
console.log("Current connected address is ", connectedAddr\[0\])
} catch(ex){console.error(ex.message)}
})

diox.on("connected\_address\_changed", (address: string\[\]) => {
if (address.length === 0) {
console.log("now your dapp is not connecting dio-wallet")
} else {
console.log("now you has changed the address which connected dio-wallet")
}

})
}

How to get a symbol for your DApp