Send Tokens to a Contract
Command Line Interface
junod tx wasm execute CONTRACT '{"some_endpoint":{}}' --amount 1000000ujunoTypescript
import type {Coin} from "@cosmjs/stargate"
import { SigningStargateClient, StargateClient, type StdFee } from '@cosmjs/stargate';
import type { OfflineAminoSigner } from '@cosmjs/amino';
import type { OfflineDirectSigner } from '@cosmjs/proto-signing';
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';
let RPC = "https://rpc.juno.strange.love"
const get_wallet_for_chain = async (
chain_id: string
): Promise<OfflineAminoSigner | OfflineDirectSigner> => {
// open keplr
const keplr = window as KeplrWindow;
if (keplr === undefined) {
throw new Error('Keplr not found');
}
let signer = keplr.getOfflineSignerAuto;
if (signer === undefined) {
throw new Error('Keplr not found');
}
return signer(chain_id);
};
let wallet = await get_wallet_for_chain("juno-1");
let address = (await wallet.getAccounts())[0].address;
let from_client = await SigningCosmWasmClient.connectWithSigner(RPC, wallet, {
prefix: "juno"
});
const msg = {"some_endpoint": {}}
let fee: StdFee = {
amount: [{amount: "5000",denom: "ujuno"}],
gas: "500000"
}
let send_amount: Coin = {
amount: "100000",
denom: "ujuno"
}
await from_client.execute(
address,
REVIEWS_CONTRACT_ADDRESS,
msg,
fee,
"memo",
send_amount,
).then((res) => {
console.log(`Success @ height ${res.height}\n\nTxHash: ${res.transactionHash}`)
});ts-codegen
Last updated
Was this helpful?