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.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.
}
type Hash = string // bech32 encoded.
cosmos.sendTransaction(chainId: string, rawTransaction: string, mode?: SendMode): Promise<Hash>
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 bech32
encoded
transaction hash.