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 nameicon
(string) - CyberApp icon URL
Instance Properties
name
(string) - CyberApp nameicon
(string) - CyberApp icon URLcyberWallet
(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 CyberAccountoptimism
(Chain) - Supported chain for CyberAccountoptimismGoerli
(Chain) - Supported chain for CyberAccountpolygon
(Chain) - Supported chain for CyberAccountpolygonMumbai
(Chain) - Supported chain for CyberAccountarbitrum
(Chain) - Supported chain for CyberAccountarbitrumGoerli
(Chain) - Supported chain for CyberAccountlinea
(Chain) - Supported chain for CyberAccountlineaTestnet
(Chain) - Supported chain for CyberAccountbase
(Chain) - Supported chain for CyberAccountbaseGoerli
(Chain) - Supported chain for CyberAccountopBnb
(Chain) - Supported chain for CyberAccountopBnbTestnet
(Chain) - Supported chain for CyberAccountscrollSepolia
(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 CyberAccountownerAddress
(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 namedetails
(string) - Error detailsshortMessage
(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 CyberWalletisChainUnsupported(chainId: number)
- Checks if the chain is supported by CyberWallet