varaconnect
Version:
SDK to connect WalletConnect with Vara Network
57 lines (56 loc) • 1.81 kB
JavaScript
import { WalletConnect } from "../services/WalletConnect";
class WalletConnectService {
constructor() {
this.connected = false;
this.accounts = [];
this.wcService = new WalletConnect();
}
async enableWalletConnect(network = "test") {
try {
await this.wcService.setNamespace("polkadot");
await this.wcService.enable(network);
this.accounts = await this.wcService.getAccounts();
this.connected = true;
console.log("Wallet connected successfully:", this.accounts);
}
catch (error) {
console.error("WalletConnect Error:", error);
throw error;
}
}
async signTransaction(payload) {
if (!this.connected) {
throw new Error("Wallet not connected");
}
try {
const signature = await this.wcService.signTransaction(payload);
console.log("Transaction signed:", signature);
return signature;
}
catch (error) {
console.error("Error signing transaction:", error);
throw error;
}
}
async signMessage(raw) {
if (!this.connected) {
throw new Error("Wallet not connected");
}
try {
const signature = await this.wcService.signMessage(raw);
console.log("Message signed:", signature);
return signature;
}
catch (error) {
console.error("Error signing message:", error);
throw error;
}
}
isConnected() {
return this.connected;
}
getAccounts() {
return this.accounts;
}
}
export const walletConnectService = new WalletConnectService();