メインコンテンツへスキップ

Documentation Index

Fetch the complete documentation index at: https://injectivelabs-mintlify-jp-native-developers-first-half.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

MsgBroadcaster抽象化クラスは、Injective上でトランザクションを簡単にブロードキャストする方法です。これを使用すると、トランザクションにパックしたいMessageと署名者のアドレスを渡すだけで、トランザクションを準備、署名、ブロードキャストできます。 使用例は当方のHelixデモリポジトリを参照してください。broadcastメソッドに渡せるメッセージについては、ドキュメントのCore Modulesセクションで例を確認できます。

MsgBroadcaster + Wallet Strategy

このMsgBroadcasterは、Wallet Strategyクラスと併用して分散型アプリケーションを構築するために使用されます。 MsgBroadcasterクラスをインスタンス化(および使用)するには、次のコードスニペットを使用できます。
import { toChainFormat } from "@injectivelabs/utils";
import { ChainId, EvmChainId } from "@injectivelabs/ts-types";
import { MsgSend } from "@injectivelabs/sdk-ts/core/modules";
import { MsgBroadcaster } from "@injectivelabs/wallet-core";
import { WalletStrategy } from "@injectivelabs/wallet-strategy";
import { Network, getNetworkEndpoints } from "@injectivelabs/networks";

export const evmRpcEndpoint = "";
export const walletStrategy = new WalletStrategy({
  chainId: ChainId.Mainnet,
  evmOptions: {
    rpcUrl: evmRpcEndpoint,
    evmChainId: EvmChainId.Mainnet,
  },
  strategies: {},
});

export const msgBroadcaster = new MsgBroadcaster({
  walletStrategy,
  simulateTx: true,
  network: Network.Mainnet,
  endpoints: getNetworkEndpoints(Network.Mainnet),
  gasBufferCoefficient: 1.1,
});

// Usage Example
const signer = "inj1...";

const msg = MsgSend.fromJSON({
  amount: {
    denom: "inj",
    amount: toChainFormat(0.01, 18).toFixed(),
  },
  srcInjectiveAddress: signer,
  dstInjectiveAddress: "inj1...",
});

// Prepare + Sign + Broadcast the transaction using the Wallet Strategy
await msgBroadcaster.broadcast({
  injectiveAddress: signer,
  msgs: msg,
});

Constructor/Broadcastオプション

MsgBroadcasterのコンストラクタおよびトランザクションのブロードキャスト時に渡される一部のオプションをオーバーライドできます。各フィールドのインターフェースと意味は次のとおりです。
import { Msgs } from '@injectivelabs/sdk-ts/core/modules'
import { ChainId, EvmChainId } from '@injectivelabs/ts-types'
import { Network, NetworkEndpoints } from '@injectivelabs/networks'
import type { WalletStrategy } from '../strategies'

export interface MsgBroadcasterOptions {
  network: Network /** network configuration (chainId, fees, etc) - Network.MainnetSentry for mainnet or  Network.TestnetSentry for testnet */
  endpoints?: NetworkEndpoints /** optional - overriding the endpoints taken from the `network` param **/
  feePayerPubKey?: string /** optional - if you are using the fee delegation service, you can set the fee payer so you don't do an extra query to the Web3Gateway */
  simulateTx?: boolean /** simulate the transaction before broadcasting + get gas fees needed for the transaction */
  txTimeout?: number /** optional - blocks to wait for tx to be included in a block **/
  walletStrategy: WalletStrategy
  gasBufferCoefficient?: number /** optional - as gas buffer to add to the simulated/hardcoded gas to ensure the transaction is included in a block */
}

export interface MsgBroadcasterTxOptions {
  memo?: string /** MEMO added to the transaction **/
  injectiveAddress: string /** the signer of the transaction **/
  msgs: Msgs | Msgs[] /** the messages to pack into a transaction **/

  /*
  *** overriding the hardcoded gas/simulation -
  *** depending on the simulateTx parameter in
  *** the MsgBroadcaster constructor
  */
  gas?: {
    gasPrice?: string
    gas?: number /** gas limit */
    feePayer?: string
    granter?: string
  }
}

endpointsをオーバーライドし、自身のインフラストラクチャを使用するには(推奨)、 Networksページで、提供すべきエンドポイントと そのセットアップ方法について詳しく読んでください。

MsgBroadcaster with Private Key

このMsgBroadcasterは秘密鍵と併用されます(主にCLI環境で使用されます)。Constructor/broadcastのオプションはMsgBroadcasterとほぼ同様です。
import { toChainFormat } from "@injectivelabs/utils";
import { MsgSend } from "@injectivelabs/sdk-ts/core/modules";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";

export const msgBroadcasterWithPk = new MsgBroadcasterWithPk({
  privateKey: `0x...` /** private key hash or PrivateKey class from sdk-ts */,
  network: NETWORK,
});

// Usage Example
const signer = "inj1...";

const msg = MsgSend.fromJSON({
  amount: {
    denom: "inj",
    amount: toChainFormat(0.01, 18).toFixed(),
  },
  srcInjectiveAddress: signer,
  dstInjectiveAddress: "inj1...",
});

// Prepare + Sign + Broadcast the transaction using the Private Key
await msgBroadcasterWithPk.broadcast({
  injectiveAddress: signer,
  msgs: msg,
});
Last modified on May 14, 2026