Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
MsgExecuteContract
import { Network } from "@injectivelabs/networks"; import { toChainFormat } from "@injectivelabs/utils"; import { MsgSend } from "@injectivelabs/sdk-ts/core/modules"; import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx"; const privateKey = "0x..."; const injectiveAddress = "inj1..."; const amount = { denom: "inj", amount: toChainFormat(1).toFixed(), }; const msg = MsgSend.fromJSON({ amount, srcInjectiveAddress: injectiveAddress, dstInjectiveAddress: injectiveAddress, }); const txHash = await new MsgBroadcasterWithPk({ privateKey, network: Network.Testnet, }).broadcast({ msgs: msg, }); console.log(txHash);
import { Network } from "@injectivelabs/networks"; import { toChainFormat } from "@injectivelabs/utils"; import { MsgMultiSend } from "@injectivelabs/sdk-ts/core/modules"; import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx"; const privateKey = "0x..."; const injectiveAddress = "inj1..."; const denom = "inj"; const decimals = 18; const records = [ /** 在此添加记录 */ ] as { address: string; amount: string /* 人类可读的数字 */; }[]; const totalToSend = records.reduce((acc, record) => { return acc.plus(toChainFormat(record.amount, decimals)); }, toChainFormat(0)); const msg = MsgMultiSend.fromJSON({ inputs: [ { address: injectiveAddress, coins: [ { denom, amount: totalToSend.toFixed(), }, ], }, ], outputs: records.map((record) => { return { address: record.address, coins: [ { amount: toChainFormat(record.amount, decimals).toFixed(), denom, }, ], }; }), }); const txHash = await new MsgBroadcasterWithPk({ privateKey, network: Network.Testnet, }).broadcast({ msgs: msg, }); console.log(txHash);