Strategy
The main purpose of the @injectivelabs/wallet-strategy is to offer developers a way to have different wallet implementations on Injective. All of these wallets implementations are exposing the same ConcreteStrategy interface which means that users can just use these methods without the need to know the underlying implementation for specific wallets as they are abstracted away.
To start, you have to make an instance of the WalletStrategy class which gives you the ability to use different wallets out of the box. You can switch the current wallet that is used by using the setWallet method on the walletStrategy instance.
Let's have a look at the methods that WalletStrategy strategy exposes and what they mean:
Both Ethereum and Cosmos native wallets:
getAddressesgets the addresses from the connected wallet strategy. This method returns the Ethereum addresses for Ethereum native wallets (strategies) and Injective addresses for Cosmos native wallets (strategies).signTransactionsigns a transaction using the corresponding wallet type method (signCosmosTransactionfor Cosmos native wallets,signEip712TypedDatafor Ethereum native wallets)sendTransactionsigns a transaction using the corresponding wallet type method (needs asentryEndpointpassed to the options if we wanna use it on Ethereum native wallets - explanation can be found below)getWalletDeviceTypereturns the wallet connection type (mobile, browser, hardware),
Cosmos native wallets:
signCosmosTransactionsigns an Injective transaction using the connected wallet strategy,getPublicKeyget the public key for the Cosmos native wallet strategies,
Ethereum native wallets:
getEthereumChainIdget the chain id for the Ethereum native wallet strategies,signEip712TypedDatasigns an EIP712 typed data using the connected wallet strategy,sendEvmTransactionsends an Ethereum Web3 transaction using the connected wallet strategy,signEvmTransactionsigns an Ethereum Web3 transaction using the connected wallet strategy,getEvmTransactionReceiptget the transaction receipt for Ethereum native transactions for the wallet strategy,
Arguments
The arguments passed to the WalletStrategy have the following interface:
Note: When we wanna use the sendTransaction on Ethereum native wallets alongside the other options (chainId and address) we also need to pass a gRPC endpoint to a sentry to broadcast the transaction. This is needed because from Ethereum native wallets, we don't have access to a broadcastTx method as we have on Keplr or Leap to broadcast the transaction using the wallet's abstraction so we have to broadcast it on the client side directly to the chain.
Example usage
Last updated
