Signing
As described earlier, one of the features of Quirks is its ability to let you access its state globally, regardless of the framework you are using.
In addition, to improve the development experience, we have been working on
some features that deal with signing a transaction. For this reason we provide
you with a number of utilities within @quirks/store
.
The functions presented below, are not reactive, it is recommended to use the
specific packages of each framework for reactive behaviors, such as
@quirks/react
or @quirks/vue
getAddress
Returns the current account address by chainName
getChain
Returns chain info by chainName
getOfflineSigner
Returns a valid signer class by chainId
and signerType
(auto
, amino
or direct
).
getSigningStargateClient
Returns an instance of CosmJS Signing Stargate Client
getSigningCosmWasmClient
Returns an instance of CosmJS Signing CosmWasm Stargate Client
sign
Signs a transaction using CosmJS Stargate Client on a given chainName
.
Allows specifying messages, fees, signer type, memo, explicitSignerData and timeoutHeight.
signCW
Signs a CosmWasm transaction using CosmJS Stargate Client on a given
chainName
.
Allows specifying messages, fees, signer type, memo, explicitSignerData and timeoutHeight.
signArbitrary
Signs an arbitrary message using the wallet on a given chainId
. Allows
specifying the signer and message data. (Useful for use cases such
as auth token generation).
broadcast
Broadcasts a TxRaw
transaction on a given chainName
. Optional parameters
allow specifying timeout and poll interval.
broadcastSync
Broadcasts a TxRaw
transaction synchronously on a given chainName
.
It returns the hash of the transaction (no waiting through polling).
It's useful for use cases where you want to trace the tx using some other
method, such as websocket or state machines.
Sign a send
message
In this example we want to sign a send
message. We'll use the osmojs
library
to compose the message, but you can use whatever library is most convenient
for you.
Install osmojs
Connect a wallet using the methods described in the "Getting Started" section, based on your framework (react or vue).
Create a send
function. For example purposes only, we will make a
"self-send" to the same connected address on the Osmosis chain.
As you may have noticed, osmojs
is imported using dynamic imports,
to optimise the bundle size.
Call the function from anywhere you want to use it. For example, in React, you could do something like this.
To track the state of transactions and your dapp in general, we recommend using tanstack query. New code examples will be provided in the future.