Skip to content

API Reference

CyberApp is the only class you need to create a CyberApp.

CyberApp

The CyberApp interface provides a way for dapps to interact with CyberWallet.

Constructor

CyberApp(options)

Parameters

  • options
    • name (string) - CyberApp name
    • icon (string) - CyberApp icon URL

Instance Properties

  • name (string) - CyberApp name
  • icon (string) - CyberApp icon URL
  • cyberWallet (CyberWallet) - CyberWallet instance

Instance Methods

  • async start() - Starts the app and connects to the CyberAccount website, returns the user's CyberAccount info

Examples

import { CyberApp } from "@cyberlab/cyber-app-sdk";
 
const app = new CyberApp({ name: "Example", icon: "icon.png" });
 
app.start().then((cyberAccount) => {
  console.log(cyberAccount); // {address: '0x1234...', ownerAddress: '0x1234...'}
});

CyberWallet

You can switch between different chains by accessing the chain property of CyberWallet.

Instance Properties

  • connected (boolean) - Indicates whether the app is connected to CyberAccount
  • optimism(Chain) - Supported chain for CyberAccount
  • optimismGoerli(Chain) - Supported chain for CyberAccount
  • polygon(Chain) - Supported chain for CyberAccount
  • polygonMumbai(Chain) - Supported chain for CyberAccount
  • arbitrum(Chain) - Supported chain for CyberAccount
  • arbitrumGoerli(Chain) - Supported chain for CyberAccount
  • linea(Chain) - Supported chain for CyberAccount
  • lineaTestnet(Chain) - Supported chain for CyberAccount
  • base(Chain) - Supported chain for CyberAccount
  • baseGoerli(Chain) - Supported chain for CyberAccount
  • opBnb(Chain) - Supported chain for CyberAccount
  • opBnbTestnet(Chain) - Supported chain for CyberAccount
  • scrollSepolia(Chain) - Supported chain for CyberAccount

Examples

Transfer native tokens on Optimism

app.cyberWallet.optimism.sendTransaction({
  to: "0x370CA01D7314e3EEa59d57E343323bB7e9De24C6",
  value: "1000000000000000",
  data: "0x",
});

Transfer native tokens on Polygon

app.cyberWallet.polygon.sendTransaction({
  to: "0x370CA01D7314e3EEa59d57E343323bB7e9De24C6",
  value: "1000000000000000",
  data: "0x",
});

CyberAccount

The CyberAccount interface holds the information of a user's CyberAccount.

Instance Properties

  • address (string) - Address of the CyberAccount
  • ownerAddress (string) - Address of the CyberAccount owner account

Chain

The Chain interface provides the basic chain info and functionalities like sendTransaction.

Instance Properties

  • id (number) - Chain ID

Instance Methods

  • async sendTransaction() - Sends a transaction on the chain, returns a transaction hash if it's successful

Error

All errors thrown by the CyberApp SDK are instances of Error.

Instance Properties

  • name (string) - Error name
  • details (string) - Error details
  • shortMessage (string) - Short error message

Common Errors

  • Connection error - Thrown when the app connects to the CyberWallet website failed
{
  "name": "ConnectionError",
  "details": "<details>",
  "shortMessage": "Connection failed"
}
  • Sending transaction error - Thrown when sending a transaction failed
{
  "name": "SendTransactionError",
  "details": "<details>",
  "shortMessage": "Transaction failed"
}

Examples

import { CyberApp, EventError, ErrorType } from "@cyberlab/cyber-app-sdk";
 
app?.cyberWallet?.polygonMumbai
  .sendTransaction(
    {
      to: address as Hex,
      value: parseUnits("0.001", 18).toString(),
      data: "0x",
    },
    { description: "Transfering native tokens" }
  )
  .catch((err: EventError) => {
    if (err.name === ErrorType.SendTransactionError) {
      console.log(err.shortMessage); // Transaction failed
    }
  });

Utility Functions

  • isCyberWallet() - Checks if the app is running in CyberWallet
  • isChainUnsupported(chainId: number) - Checks if the chain is supported by CyberWallet