Viem
CyberWallet SDK is compatible with Viem. You can create a wallet client with CyberWallet provider using Viem custom
transport. For more information about Viem, please visit the Viem documentation.
Installation
npm install @cyberlab/cyberwallet-sdk
Usage
1. Setup the SDK with your dapp information
import { CyberSdk } from "@cyberlab/cyberwallet-sdk";
const sdk = new CyberSdk(
{
dappName: "<Your Dapp Name>",
projectId: "<Your Project ID>",
customHost: "https://stg.passkey.cyber.co", // optional
chainId: 111557560, // optional
},
);
dappName
: Your Dapp nameprojectId
: The project ID is used to identify your Dapp.customHost
: The custom host URL is optional. If you don't provide it, the SDK will use the default CyberWallet host URL (https://passkey.cyber.co
). If you want to use the CyberWallet Testnet environment, you can set the custom host URL tohttps://stg.passkey.cyber.co
.chainId
: The chain ID is optional. If you don't provide it, the SDK will use the default Cyber chain ID (7560
). If you want to use the Cyber Testnet, you can set the chain ID to111557560
.
2. Create a Wallet Client with CyberWallet Provider
const cyberProvider = sdk.getCyberProvider();
const walletClient = createWalletClient({
chain: cyber,
transport: custom(cyberProvider)
})
3. Connect to CyberWallet
// connect
const connect = async () => {
return await walletClient.requestAddresses()
};
// get connected Accounts
const accounts = async () => {
return await walletClient.getAddresses()
}
It will open the CyberWallet connect page and ask the user to confirm using Passkeys. After the user confirms, the accounts
variable will contain the user's account address.
4. Sign a message
const sign = async () => {
const account = accounts[0];
const message = "Hello, world!";
const signature = await walletClient.signMessage({
account,
message,
})
return signature;
}
It will open the CyberWallet sign message page and ask the user to sign using the same Passkey. After the user confirms, CyberWallet will return the signature.
5. Send a transaction
// sendTx
const sendTx = async () => {
const account = accounts[0];
const res = await walletClient.sendTransaction({
from: account,
to: "0x1126DC7AE830415C7D6CbB2F09b1266823f490c4",
value: "100000000000000",
});
console.log('res', res)
return;
};
It will open the CyberWallet send transaction page and ask the user to confirm using the same Passkey. After the user confirms, CyberWallet will return the transaction result.
You can view the transaction details on Cyber Blockchain Explorer: mainnet, testnet.