cosmiframe
Cosmiframe assists in establishing a Cosmos wallet connection through an iframe.
An outer (parent) window can act as a wallet for an iframe.
Installation
npm install @dao-dao/cosmiframe @cosmjs/amino @cosmjs/proto-signing
Usage
This example allows an iframe to interact with Keplr connected in the parent.
- Begin listening from the parent window:
import { Cosmiframe } from '@dao-dao/cosmiframe'
const cosmiframe = new Cosmiframe()
cosmiframe.listen({
iframe: document.getElementById('iframe'),
target: window.keplr,
getOfflineSignerDirect: window.keplr.getOfflineSigner.bind(window.keplr),
getOfflineSignerAmino: window.keplr.getOfflineSignerOnlyAmino.bind(
window.keplr
),
})
- Request method calls from the iframe:
import { Cosmiframe } from '@dao-dao/cosmiframe'
const cosmiframe = new Cosmiframe()
await cosmiframe.p.enable('cosmoshub-4')
const directSigner = cosmiframe.getOfflineSignerDirect('cosmoshub-4')
const aminoSigner = cosmiframe.getOfflineSignerAmino('cosmoshub-4')
const signingClient = await SigningCosmWasmClient.connectWithSigner(
'https://rpc...',
directSigner
)