import { signals } from '@apophis-sdk/core';
import { Apophis, Bank, Cosmos, DefaultCosmosMiddlewares } from '@apophis-sdk/cosmos';
import { useComputed } from 'preact/signals';
import { useMemo } from 'preact/hooks';
Apophis.use(...DefaultCosmosMiddlewares);
Cosmos.getNetworkFromRegistry('neutrontestnet').then(network => {
signals.network.value = network;
});
function MyComponent() {
// There is no base type for messages. The only thing that matters is that the SDK knows how to
// serialize and deserialize them, which is implemented through the middleware subsystem.
const msgs = useComputed(() => [
new Bank.Send({
fromAddress: signals.address.value,
toAddress: 'neutron1...', // e.g. your own address
amount: [Cosmos.coin(1_000000n, 'untrn')], // 1 NTRN
}),
]);
const tx = useMemo(() => Cosmos.signalTx(msgs));
return (
<div>
<button onClick={() => tx.signAndBroadcast()}>
Send payment
</button>
<cosmos-gas-estimate tx={tx} />
</div>
);
}