TypeScript typings
Download bitshares-provider.d.ts and place it where TypeScript will include it, for example src/types/bitshares-provider.d.ts, or reference it from include / typeRoots in tsconfig.json.
The file augments Window, so client code can write:
import type { CubWalletProvider, CubAccount } from './types/bitshares-provider';
async function connect(): Promise<{ bts: CubWalletProvider; accounts: CubAccount[] }> {
const bts = window.bitshares;
if (!bts?.isCubWallet) throw new Error('Please install CubWallet');
const accounts = await bts.request({ method: 'bts_requestAccounts' });
return { bts, accounts };
}The typings only include methods and events that exist. request is overloaded for the four method names, and the return types match the source. Any other method name is typed as Promise<unknown> and fails at runtime with 不支持的方法: ….
CubWallet