Skip to main content

Cosmos Provider API

Exodus injects a global API into websites visited by its users at window.exodus.cosmos.

Methods

cosmos.connect(options)

interface ConnectionOptions {
chainId: string
onlyIfTrusted?: boolean
}

interface Account {
address: string // bech32 encoded.
algo: 'secp256k1' | 'ed25519' | 'sr25519'
publicKey: Uint8Array
}

cosmos.connect(options: ConnectionOptions): Promise<Account>

Use connect() to request access to the user's account. This will open a pop-up asking the user to approve the connection. If the user approves, Exodus will return account information related to the requested chain ID.

Eagerly Connecting

After the user approves a Web3 site's connection to Exodus, the site becomes trusted, which allows the site to automatically connect (eagerly connect) to Exodus on subsequent visits or page refreshes.

If you want to try to eagerly connect, you can pass the onlyIfTrusted option to connect().

try {
await window.exodus.cosmos.connect({ chainId: 'cosmos', onlyIfTrusted: true })
} catch (err) {
// { code: 4001, message: 'User rejected the request.' }
}
tip

When using onlyIfTrusted, Exodus will only connect if the site is trusted. Users will not see a pop-up if they have connected to Exodus before.

cosmos.disconnect()

cosmos.disconnect(): void

Use disconnect() to remove access to the user's account. Upon disconnection, Exodus will emit a disconnect event.

cosmos.signAminoTransaction(transaction)

interface Coin {
amount: string
denom: string
}

interface Fee {
amount: Coin[]
gas: string
granter?: string
payer?: string
}

interface AminoMessage {
type: string
value: any
}

interface AminoTransaction {
account_number: string
chain_id: string
fee: Fee
memo: string
msgs: AminoMessage[]
sequence: string
}

interface PublicKeyInfo {
type: string
value: string
}

interface SignatureInfo {
pub_key: PublicKeyInfo
signature: string
}

interface AminoSignResponse {
signed: AminoTransaction
signature: SignatureInfo
}

cosmos.signAminoTransaction(transaction: AminoTransaction): Promise<AminoSignResponse>

Use signAminoTransaction() to request the Exodus user to sign an Amino-encoded transaction without submitting it to the network. This method returns a Promise that resolves to an object of type AminoSignResponse, which contains the signed transaction (AminoTransaction) and the corresponding signature information (SignatureInfo).

cosmos.signTransaction(transaction)

interface Transaction {
accountNumber: string
authInfoBytes: Uint8Array
bodyBytes: Uint8Array
chainId: string
}

interface SignResponse {
signed: Transaction
signature: SignatureInfo
}

cosmos.signTransaction(transaction: Transaction): Promise<SignResponse>

Use signTransaction() to request the Exodus user to sign a Protobuf-encoded transaction without submitting it to the network. It returns a Promise that resolves to an object of type SignResponse, which contains the signed transaction (Transaction) and the corresponding signature information (SignatureInfo).

cosmos.sendTransaction(chainId, rawTransaction, mode)

enum SendMode {
Block = "block", // Resolves once a transaction is confirmed.
Sync = "sync", // Resolves once a transaction is successfully submitted to a node.
Async = "async", // Resolves immediately.
}

cosmos.sendTransaction(chainId: string, rawTransaction: Uint8Array, mode?: SendMode): Promise<Uint8Array>

Use sendTransaction() to broadcast a previously signed transaction to the network. If the SendMode parameter is missing, the Sync send mode will be used by default. It returns a Promise that resolves to the transaction hash.

Events

connect

cosmos.on('connect', handler: (account: Account) => void)

The Exodus provider emits this event upon successfully connecting to the wallet.

disconnect

cosmos.on('disconnect', handler: () => void)

The Exodus provider emits this event if it becomes unable to submit RPC requests to the current chain.

Once disconnect has been emitted, the provider will not accept any new requests until the connection to the chain has been re-established.

accountChanged

cosmos.on('accountChanged', handler: (account: Account) => void)

The Exodus provider emits this event whenever the address returned from calling the connect method changes. This means that accountChanged will be emitted whenever the user switches accounts in Exodus.