Your first transaction
Send 1 usaf to yourself on testnet. Same operation on every platform tab below.
Constants (all platforms):
| Name | Value |
|---|---|
CHAIN_ID | safro-testnet-1 |
RPC | https://rpc.testnet.safrochain.com:443 |
REST | https://rest.testnet.safrochain.com |
DENOM | usaf |
Prerequisites: funded testnet address.
- Web (TypeScript)
- React Native
- Flutter (CosmJS)
- CLI (dev)
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningStargateClient, assertIsDeliverTxSuccess } from "@cosmjs/stargate";
const RPC = "https://rpc.testnet.safrochain.com:443";
const CHAIN_ID = "safro-testnet-1";
const DENOM = "usaf";
// Dev only: use Cosmos Kit offline signer in production browser apps.
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(process.env.MNEMONIC!, {
prefix: "addr_safro",
});
const [{ address }] = await wallet.getAccounts();
const client = await SigningStargateClient.connectWithSigner(RPC, wallet, {
gasPrice: { denom: DENOM, amount: "0.05" },
});
const res = await client.sendTokens(address, address, [{ denom: DENOM, amount: "1" }], "auto", "first tx");
assertIsDeliverTxSuccess(res);
console.log(res.transactionHash);
Production web apps: connect via Cosmos Kit instead of a mnemonic.
import * as SecureStore from "expo-secure-store";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningStargateClient, assertIsDeliverTxSuccess } from "@cosmjs/stargate";
const RPC = "https://rpc.testnet.safrochain.com:443";
const DENOM = "usaf";
const mnemonic = await SecureStore.getItemAsync("safro_mnemonic");
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic!, { prefix: "addr_safro" });
const [{ address }] = await wallet.getAccounts();
const client = await SigningStargateClient.connectWithSigner(RPC, wallet, {
gasPrice: { denom: DENOM, amount: "0.05" },
});
const res = await client.sendTokens(address, address, [{ denom: DENOM, amount: "1" }], "auto", "first tx");
assertIsDeliverTxSuccess(res);
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { SigningStargateClient, assertIsDeliverTxSuccess } from '@cosmjs/stargate';
const RPC = 'https://rpc.testnet.safrochain.com:443';
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: 'addr_safro' });
const [{ address }] = await wallet.getAccounts();
const client = await SigningStargateClient.connectWithSigner(RPC, wallet, {
gasPrice: { denom: 'usaf', amount: '0.05' },
});
const res = await client.sendTokens(address, address, [{ denom: 'usaf', amount: '1' }], 'auto', 'first tx');
assertIsDeliverTxSuccess(res);
Run CosmJS in a JS bridge (flutter_js) or use Cosmos Kit + WalletConnect for external wallets. See Flutter guide.
ADDR=$(safrochaind keys show dev -a --keyring-backend file)
safrochaind tx bank send dev "$ADDR" 1usaf \
--chain-id safro-testnet-1 \
--node https://rpc.testnet.safrochain.com:443 \
--gas auto --gas-adjustment 1.3 \
--gas-prices 0.05usaf \
--keyring-backend file \
--yes
Next steps
- Signing overview: full sign and broadcast flow
- Simulate gas and fees