Skip to content

Instantly share code, notes, and snippets.

@justinbarry
Created June 7, 2024 18:53
Show Gist options
  • Save justinbarry/de23642a04e94aebfb5a67502df1fa82 to your computer and use it in GitHub Desktop.
Save justinbarry/de23642a04e94aebfb5a67502df1fa82 to your computer and use it in GitHub Desktop.
An example of how to send multiple send token messages inside one transaction
import {MsgSendEncodeObject, SigningStargateClient, StdFee} from "@cosmjs/stargate";
import {DirectSecp256k1Wallet, OfflineDirectSigner} from "@cosmjs/proto-signing";
import {fromHex} from "@cosmjs/encoding";
(async function () {
const recipients = [
'xion1adgdmkfrpgu749d5qahwxmu3jzcp77mm5wxddq',
'xion19jerqdcz7u2220q2xj078hndcqv8z8kjj3trsp',
'xion1te8gp204fserypat7h8mere5pz39afsn6ssn67',
'xion1a3yrnqxufnxgj30lngtt2dx4veac0e20lmhxg9',
'xion1w5xgrzzqs25r8pfma9g8dv4supm90z25rtvfxm',
'xion1skk4slrd3la5fuurley80arphq8vt4t46h8l5r',
'xion138wn6utkfcw8qu7ye88p44g9nesqj6vyw3s5el',
'xion198nsjkxwzk44spn2tf23zfrr3gek7c3l5jmcdv',
'xion1apwz9lya6ddelxslsvm24fr0qk8gjdrpnqywxv',
'xion14rftnp3rt6pa3c5sass733f0w99tf45302ptgn'
]
const signer: OfflineDirectSigner = await DirectSecp256k1Wallet.fromKey(
fromHex(process.env.PRIVATE_KEY),
"xion"
);
const client = await SigningStargateClient.connectWithSigner(
"https://rpc.xion-testnet-1.burnt.com",
signer
)
const [account] = await signer.getAccounts()
const senderAddress = account.address;
const sendMsgs: MsgSendEncodeObject[] = recipients.map((recipientAddress:string) => ({
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: {
fromAddress: senderAddress,
toAddress: recipientAddress,
amount: [{
denom: 'uxion',
amount: '1'
}],
},
}));
const fee: StdFee = {
amount: [{denom: "uxion", amount: "0"}],
gas: "42424242",
}
const result = await client.signAndBroadcast(senderAddress, sendMsgs, fee);
console.log('result', result);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment