# Send tokens to a Contract

## Command Line Interface

When you execute a message, a user can also pass through a flag which sends funds from their account to the contract to do logic. You can check if a user sends any funds in your contract's execute endpoint with the `info.funds` array of Coins sent by the user. These funds then get added to the contracts balance just like any other account. So it is up to you as the developer to ensure to save how many funds each user has sent via a BTreeMap or other object storage in state (if they can redeem funds back at a later time).

To send funds to a contract with some arbitrary endpoint, you use the `--amount` flag.

```sh
oraid tx wasm execute CONTRACT '{"some_endpoint":{}}' --amount 1000000orai
```

{% hint style="info" %}
If the "some\_endpoint" execute errors on the contract, the funds will remain in the users account.
{% endhint %}

## Typescript

```typescript
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();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.orai.io/developer-guides/cosmwasm-contract/send-token-to-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
