Wallet Integration#

In a browser dApp, never ask a user for their seed phrase or private key. Instead, let the user sign transactions with their own wallet through Cubensis Connect, DecentralChain’s browser extension wallet. There are two ways to integrate it.

Direct: the CubensisConnect browser API#

On any page served over http/https with the extension installed, a global CubensisConnect object is injected into the page. This is what Signer’s provider uses internally — you can also call it directly if you don’t need Signer’s abstraction:

Method

Description

publicState()

Current account, network, and balance info, if the site is trusted

auth(data)

Authenticate the user, returning a signed proof of account ownership

signTransaction(tx)

Sign a transaction without broadcasting

signAndPublishTransaction(tx)

Sign and broadcast a transaction

signOrder(order) / signAndPublishOrder(order)

Sign (and optionally broadcast) a DEX order

signCancelOrder(order) / signAndPublishCancelOrder(order)

Sign (and optionally broadcast) an order cancellation

encryptMessage(msg, publicKey) / decryptMessage(msg, publicKey)

Encrypt/decrypt a message for a given public key

on(event, callback)

Subscribe to wallet events (account/network changes)

The extension asks the user to explicitly trust a new site the first time it calls any method other than on. Until trusted, all other calls reject with {message: "Api rejected by user", code: 12}. See the Cubensis Connect repository for the complete method list and response shapes, and cubensis-connect-types for TypeScript definitions.

if (window.CubensisConnect) {
  const authData = await window.CubensisConnect.auth({ data: 'My dApp Login' });
  console.log('Authenticated address:', authData.address);
}