About the Wallet API

Xterium's Wallet API provides a seamless interface for interacting with the Xterium wallet extension. The API allows developers to request wallet connections, sign transactions, and interact with the blockchain. The API is designed to be simple, secure, and developer-friendly, enabling dApps to integrate Xterium wallet functionality effortlessly.

The Xterium Wallet API consists of a JavaScript API injected into websites visited by users, similar to MetaMask's window.ethereum provider. This API allows dApps to interact with the user's wallet, request permissions, and perform blockchain operations through the window.xterium global object.

Xterium Provider API

Xterium injects a global JavaScript API into websites via window.xterium. This API allows dApps to:

Check if Xterium is Installed

Before using it, check if the Xterium provider exists:
Steps:
  1. Open your web app or dApp.
  2. Check if window.xterium is available.
  3. If it’s missing, ask the user to install the extension.

Detection Example:


if (typeof window.xterium !== "undefined") {
  console.log("Xterium Wallet detected!");
} else {
  alert("Please install the Xterium Wallet extension to continue.");
}
    

How to Connect a Wallet

Function
   xterium.enableXteriumWallet()
     • This function prompts the user to select and connect their wallet. It also saves the connection state in localStorage, so the user remains connected on page refresh.

Steps to Connect a Wallet
   1. Call the function xterium.enableXteriumWallet().
   2. A popup appears showing available wallets.
   3. The user selects their wallet.
   4. The user enters their wallet password to confirm.
   5. If approved, the wallet is connected successfully.
   6. If cancelled or password is wrong, an error is thrown or alert.

Example Usage


async function connectWallet() {
	try {
     const wallet = await xterium.enableXteriumWallet()
     console.log("Connected walletL:", wallet)
    } catch (err) {
     console.error("Failed to connect wallet", err)
    }
}
    

How to Sign a Transaction

Function
   xterium.signTx({ currentNetwork, txHash })
     • This function asks the user to approve signing a transaction. It does not broadcast the transaction — it only signs it. Useful when your backend or a third-party relayer will submit the transaction later.

Steps to Sign a Transaction
   1. Make sure the wallet is already connected.
   2. Call the function xterium.signTx({ currentNetwork, txHash }).
   3. A popup appears showing the transaction details and estimated fee.
   4. The user enters their password and approves the transaction.
   5. The wallet signs the transaction but does not send it to the network.
   6. Your app receives the signed transaction data as a response.

Parameters
     • currentNetwork: Object containing RPC details (must exist in available networks).
     • txHash: Transaction hash string you want the wallet to sign.

Example Usage


async function signTransaction(){
	try {
    	const result = await xterium.signTx({
        	currentNetwork: { rpc: "https://mainnet.xterium.io"},
            txHash: "0x1234abcd5678"
        })
        console.log("Transaction signed:", result)
    } catch (err) {
    	console.error("Signing failed: ", err)
    }
}
    

How to Sign and Submit a Transaction

Function
   signAndSubmitTx(currentNetwork, txHash)
     • This function signs the transaction and automatically broadcasts it to the blockchain network. Use this for a complete, one-click approval flow.

Steps to Sign and Submit a Transaction
   1. Ensure the wallet is connected.
   2. Call the function xterium.signAndSubmitTx({ currentNetwork, txHash }).
   3. A popup appears showing the transaction details and estimated gas fee.
   4. The user enters their password to confirm.
   5. The wallet signs the transaction.
   6. The wallet submits it directly to the blockchain network.
   6. Your app receives the transaction hash and confirmation status.

Parameters
     • currentNetwork: Object containing RPC details (must exist in available networks).
     • txHash: Transaction hash string.

Example Usage


async function signAndSubmitTransaction(){
	try {
    	const response = await xterium.signAndSubmitTx({
        	currentNetwork: { rpc: "https://mainnet.xterium.io"},
            txHash: "0x9876abcd1234"
        })
        console.log("Transaction submitted:", response)
    } catch (err) {
    	console.error("Submit failed: ", err)
    }
}