# 在部署的Canister中调用方法

部署完canister后，可以模拟一个终端用户调用canister提供的方法了。本章节中，调用get方法查询counter值，increment方法增加couter值，set方法传一个参数更新counter到任意输入的值。

测试部署的程序步骤如下

1. 运行下面的命令调用get函数，该函数会读取在部署的canister当前的currentValue值

   ```
   dfx canister call my_counter get
   ```

   命令输出currentValue值为0

   ```
   (0)
   ```
2. 运行下面的命令调用increment函数，该函数会将部署的canister当前的currentValue值加1

   ```
   dfx canister call my_counter increment
   ```

   这个命令会将变量加一-改变状态-但不会有返回值
3. 再次运行下面的命令获取currentValue当前的值

   ```
   dfx canister call my_counter get
   ```

   命令返回currentValue值为1

   ```
   (1)
   ```
4. 运行额外的命令并使用不同的参数来测试其他方法\
   例如，运行类似下面的命令设置并返回counter值

   ```
   dfx canister call my_counter set '(987)'
   dfx canister call my_counter get
   ```

   返回值为987

   ```
   dfx canister call my_counter increment
   dfx canister call my_counter get
   ```

   返回值为988


---

# 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://mixdao.gitbook.io/dfinity/si-.-jiao-cheng/4.-zi-ran-shu-zi-zeng/zai-bu-shu-de-canister-zhong-tiao-yong-fang-fa.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.
