MsgBroadcaster Transaction
MsgBroadcaster + Wallet Strategy
import { MsgSend } from "@injectivelabs/sdk-ts";
import { toChainFormat } from "@injectivelabs/utils";
import { MsgBroadcaster } from "@injectivelabs/wallet-core";
import { ChainId, EvmChainId } from "@injectivelabs/ts-types";
import { WalletStrategy } from "@injectivelabs/wallet-strategy";
import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
const chainId = ChainId.Testnet; // The Injective Testnet Chain ID
const evmChainId = EvmChainId.TestnetEvm; // The Injective Evm Testnet Chain ID
export const alchemyRpcEndpoint = `https://eth-goerli.alchemyapi.io/v2/${process.env.APP_ALCHEMY_SEPOLIA_KEY}`;
export const walletStrategy = new WalletStrategy({
chainId,
evmOptions: {
evmChainId,
rpcUrl: alchemyRpcEndpoint,
},
});
export const msgBroadcaster = new MsgBroadcaster({
walletStrategy,
simulateTx: true,
network: Network.Testnet,
endpoints: getNetworkEndpoints(Network.Testnet),
gasBufferCoefficient: 1.1,
})(
// Usage Example
async () => {
const signer = "inj1...";
const msg = MsgSend.fromJSON({
amount: {
denom: "inj",
amount: toChainFormat(0.01).toFixed(),
},
srcInjectiveAddress: signer,
dstInjectiveAddress: "inj1...",
});
// Prepare + Sign + Broadcast the transaction using the Wallet Strategy
await msgBroadcastClient.broadcast({
injectiveAddress: signer,
msgs: msg,
});
}
)();Constructor/Broadcast Options
MsgBroadcaster with Private Key
Last updated
