@apophis-sdk/keplr-signer
v0.2.0-fix.1
Published
[Keplr](https://keplr.app) integration for the [Apophis Web3 SDK](../../README.md).
Downloads
172
Readme
@apophis-sdk/keplr-signer
Keplr integration for the Apophis Web3 SDK.
Installation
Install with your favorite package manager's equivalent of:
npm install @apophis-sdk/core @apophis-sdk/cosmos @apophis-sdk/keplr-signer
This package is also bundled in the @apophis-sdk/cosmos-signers
package. You will likely also want to install a frontend integration such as @apophis-sdk/preact.
Usage
Using a proper frontend integration, usage is simple:
import { signals, Signer, type NetworkConfig } from '@apophis-sdk/core';
import { Bank, Cosmos } from '@apophis-sdk/cosmos';
import { Keplr } from '@apophis-sdk/cosmos-signers';
import { WalletModal } from '@apophis-sdk/preact';
import { render } from 'preact';
Signer.register(Keplr);
const network = await Cosmos.getNetworkFromRegistry('neutrontestnet');
// set active network
signals.network.value ??= network;
// render a `WalletSelector` or `WalletModal`
render((
<div>
<UserAddress />
{!signals.account.value && <WalletModal />}
<button onClick={handleClick}>Click me!</button>
</div>
), document.getElementById('app')!);
function handleClick() {
if (!signals.signer.value || !signals.network.value) return;
const network = signals.network.value;
const signer = signals.signer.value; // agnostic of signer implementation
const tx = signer.tx([
new Bank.Send({
fromAddress: signer.address(network),
toAddress: signer.address(network),
amount: [Cosmos.coin(1_000000n, 'untrn')], // 1 $NTRN
})
]);
await tx.estimateGas(network, signer, true);
await tx.sign(network, signer);
await tx.broadcast(); // signer & network are stored internally when signed successfully
}