메시지
Bank 모듈이 내보내는 메시지와 Injective 체인과 상호작용하는 데 사용할 수 있는 메시지를 살펴보고 예제를 제공하겠습니다.MsgSend
이 메시지는 한 주소에서 다른 주소로 코인을 보내는 데 사용됩니다. 모든 TokenFactory 토큰 및 Peggy 토큰을 여기서 사용할 수 있습니다. CW20 토큰을 전송하려면 wasm 모듈 예제의MsgExecuteContract 섹션을 참조하세요.
Documentation Index
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);
