Send tokens to a Contract
Command Line Interface
oraid tx wasm execute CONTRACT '{"some_endpoint":{}}' --amount 1000000oraiTypescript
import { coin, makeCosmoshubPath } from "@cosmjs/amino";
import { GasPrice } from "@cosmjs/stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import "dotenv/config";
import { MsgExec } from "cosmjs-types/cosmos/authz/v1beta1/tx";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
const main = async () => {
const mnemonic = "YOUR_MNEMONIC_HERE";
const chainInfo = {
chainId: "Oraichain",
rpcEndpoint: "https://rpc.orai.io",
prefix: "orai",
gasPrice: GasPrice.fromString("0.002orai"),
feeToken: "orai",
};
const hdPath = makeCosmoshubPath(0);
// Setup signer
const offlineSigner = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: chainInfo.prefix,
hdPaths: [hdPath],
});
const { address } = (await offlineSigner.getAccounts())[0];
console.log(`Connected to ${address}`);
// Init SigningCosmWasmClient client
const client = await SigningCosmWasmClient.connectWithSigner(
chainInfo.rpcEndpoint,
offlineSigner,
{
gasPrice: chainInfo.gasPrice,
}
);
const balance = await client.getBalance(address, chainInfo.feeToken);
console.log("balance: ", balance);
const sendCoin = coin(1000, "orai");
const tx = await client.execute(
address,
"CONTRACT_ADDRESS",
"CONTRACT_MSG",
"auto",
"memo",
[sendCoin]
);
console.log("txhash: ", tx.transactionHash);
};
main();Last updated
Was this helpful?