> For the complete documentation index, see [llms.txt](https://yeasy.gitbook.io/blockchain_guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yeasy.gitbook.io/blockchain_guide/11_app_dev/chaincode_example02.md).

# 链码示例二：交易资产

[chaincode\_example02.go](https://github.com/yeasy/blockchain_guide/blob/master/11_app_dev/chaincode_example02.go) 使用 Go Contract API 实现两个账户之间的整数余额转账。

## 主要交易函数

* `InitAccounts`：初始化两个账户及其余额；
* `Transfer`：从一个账户向另一个账户转账；
* `ReadAccount`：读取账户余额；
* `Delete`：删除账户。

示例依赖当前 Go Contract API：

```go
import "github.com/hyperledger/fabric-contract-api-go/v2/contractapi"
```

转账逻辑会检查金额必须为正数、账户必须存在、付款账户余额必须充足。客户端应用应通过 Gateway API 的 submit 类调用提交 `Transfer`，通过 evaluate 类调用读取 `ReadAccount`。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://yeasy.gitbook.io/blockchain_guide/11_app_dev/chaincode_example02.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
