Skip to content

Commit 7bf3168

Browse files
authored
feat: execution wasm command (#10)
* add execute contract method * add execute wasm command * update cli version
1 parent 87b2595 commit 7bf3168

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cosmwasm-cli",
3-
"version": "0.0.2",
3+
"version": "0.0.5",
44
"author": "Javier Aceña <j0nl1>",
55
"description": "Cosmwasm Command Line Interface",
66
"scripts": {

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import NetworkCommand from "./commands/networks";
44
import WasmCommand from "./commands/wasm";
55

66
export default new Command("cwcli")
7-
.version("0.0.2")
7+
.version("0.0.5")
88
.description("Cosmwasm Command Line Interface")
99
.usage("[command]")
1010
.addCommand(KeysCommand)

src/commands/wasm/execute.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Command } from "commander";
2+
import { executeContract } from "../../services/wasm.service";
3+
import AddressOption from "../options/address";
4+
import NetworkOption from "../options/network";
5+
6+
export default new Command("execute")
7+
.description("execute a smart contract method")
8+
.usage("<contractAddress> <msg> --address <name> --network <name> [options]")
9+
.argument("<contractAddress>")
10+
.argument("<msg>")
11+
.addOption(AddressOption)
12+
.addOption(NetworkOption)
13+
.action(executeContract);

src/commands/wasm/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { Command } from "commander";
22
import UploadCommand from "./upload";
33
import InstantiateCommand from "./instantiate";
44
import QueryCommand from "./query";
5+
import ExecuteCommand from "./execute";
56

67
export default new Command("wasm")
78
.description("Wasm transaction subcommands")
89
.usage("[command]")
910
.argument("[command]")
1011
.addCommand(UploadCommand)
1112
.addCommand(QueryCommand)
13+
.addCommand(ExecuteCommand)
1214
.addCommand(InstantiateCommand);

src/commands/wasm/query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import NetworkOption from "../options/network";
44

55
export default new Command("query")
66
.description("Querying commands for contracts")
7-
.usage("<contract> <msg> [options]")
8-
.argument("<contract>")
7+
.usage("<contractAddress> <msg> [options]")
8+
.argument("<contractAddress>")
99
.argument("<msg>")
1010
.addOption(NetworkOption)
1111
.action(queryContract);

src/services/wasm.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export const queryContract = async (contractAddress: string, msg: string, opts:
4747
console.info("Query succeeded. Receipt:", util.inspect(queryReceipt, false, null, true));
4848
};
4949

50+
export const executeContract = async (contractAddress: string, msg: string, opts: WasmOptions) => {
51+
const { client, address } = await getSigningClientAndAddress(opts.network, opts.address);
52+
53+
const executeReceipt = await client.execute(address, contractAddress, JSON.parse(msg), "auto");
54+
console.info("Execute succeeded. Receipt:", util.inspect(executeReceipt, false, null, true));
55+
};
56+
5057
const getNetworkAndKey = async (chainId: string, addressName: string): Promise<{ network: Network; key: Key }> => {
5158
const network = getNetwork(chainId);
5259
const key = await getKey(addressName);

0 commit comments

Comments
 (0)