> 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_example01.md).

# 链码示例一：信息公证

[chaincode\_example01.go](https://github.com/yeasy/blockchain_guide/blob/master/11_app_dev/chaincode_example01.go) 使用 Go Contract API 实现一个最小键值账本：

* `InitLedger`：初始化 `hello_world` 的值；
* `Write`：创建或更新指定 key 的 value；
* `Read`：读取指定 key 的 value。

代码入口使用 `contractapi.NewChaincode` 创建链码实例，并调用 `Start` 由 Fabric peer 托管执行。

```go
func main() {
	chaincode, err := contractapi.NewChaincode(&SmartContract{})
	if err != nil {
		fmt.Printf("Error creating chaincode: %s", err)
		return
	}
	if err := chaincode.Start(); err != nil {
		fmt.Printf("Error starting chaincode: %s", err)
	}
}
```

客户端应用在 Fabric v2.4+ 中应通过 Gateway API 调用合约。读取状态时使用 evaluate 类调用 `Read`；修改状态时使用 submit 类调用 `Write`。


---

# 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_example01.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.
