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.
If the "some_endpoint" execute errors on the contract, the funds will remain in the users account.
Typescript
ts-codegen
The cosmology toolkit has some useful typescript tools for interacting with your smart contracts. The repo can be found at https://github.com/CosmWasm/ts-codegen, with setup and query tutorials in Query A Contract section of this documentation.
Here are some video tutorials:
Last updated