Skip to content

Latest commit

 

History

History
108 lines (64 loc) · 4.81 KB

INTEGRATING-WALLETS.md

File metadata and controls

108 lines (64 loc) · 4.81 KB

How to Integrate your Wallet into Cosmos Kit

1️⃣ Prepare basic information for wallet

Required properties

Key Type Comment
name WalletName = string identifier
prettyName string display name
mode WalletMode = 'extension' | 'wallet-connect' wallet client type
mobileDisabled* boolean display on mobile or not

* <span style={{fontSize: '0.85rem'}}> Usually true when mode is wallet-connect, false when mode is extension.

Optional properties

Key Type Comment
rejectMessage string error message when reject permission to wallet app/extension
connectEventNames string[] window event names to fire auto-connect
downloads Downloads wallet app/extension download information
logo string wallet logo url, display on default modal

Examples

2️⃣ Implement WalletClient

MainWallet is a class organizing all ChainWallets. It should extend MainWalletBase class, in which protected _chainWallets property stores all ChainWallets.

Required methods

Key Type
getAccount (chainId: string) => Promise<WalletAccount>*
getOfflineSigner (chainId: string) => Promise<OfflineSigner> | OfflineSigner

* Type WalletAccount

interface WalletAccount {
  name?: string; // username
  address: string;
}

Optional methods

Key Type Comment
enable (chainIds: string | string[]) => Promise<void> give permission for the webpage to access wallet
addChain (chainInfo: ChainRecord) => Promise<void> add new Cosmos-SDK based blockchains that isn't natively integrated to wallet app/extension

Examples

3️⃣ Extend ChainWalletBase

Create a ChainWallet class that extends ChainWalletBase. ChainWallet provides wallet information for a particular chain, e.g. address, offlineSigner, etc.

ChainWalletBase has implemented a bunch of methods such as wallet connection, sign, broadcast, etc. [learn more]. Therefore, normally you don't need to do any extra work inside ChainWallet. But feel free to overwrite these methods or add new methods/properties if customization is needed to meet new demand.

Examples

4️⃣ Extend MainWalletBase

Create a MainWallet class that extends MainWalletBase. MainWallet organizes all ChainWallets, which are stored in protected member _chainWallets.

Note: Class ChainWallet created in Step 3 is required in MainWalletBase construction.

Required methods

Key Type
fetchClient () => WalletClient | undefined | Promise<WalletClient | undefined>*

* <span style={{fontSize: '0.85rem'}}> WalletClient is the one implemented in Step 2.

Also, feel free to overwrite methods in MainWalletBase or add new methods/properties if necessary.

Examples

5️⃣ Get MainWallet instance

You can construct your MainWallet Instance according to your MainWallet construct method now. Usually the walletInfo object prepared in Step 1 is imported here as a construction argument.

Examples

Last but not least, append this instance to the wallets property of WalletProvider.