From 82d971a67180cc7e99ff844614e19d48e6b85a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B5=E5=AE=AA=E7=91=9E?= <9198107+min-xianrui@user.noreply.gitee.com> Date: Mon, 24 Mar 2025 15:44:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index adf8f72..8ebeb44 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # Go workspace file go.work + diff --git a/README.md b/README.md index 70ddc19..89f816c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,61 @@ -# block +### Node.js +- **版本**: 16.x 或更高 + - **下载命令**: + ```bash + sudo apt install nodejs + sudo apt install npm + npm install + ``` +- **检查是否安装**: + - 示例: + ```bash + node -v + npm -v + ``` +`` +**打开Ganache**: +- 示例: +- 点击QUICKSTART(这是快速部署,如果能看懂英文,可以试试NEW WORKPLACE) +- 点击第一个账户(或者随便) +- 点击右边的钥匙会出现两行奇怪的数字,双击下面那个然后Ctrl+c复制 +- 把它放到根目录的config.json和hardhat.config.js的YOUR_PRIVATE_KEY(记得config.json的密钥前面把0x去掉,另一个不用去掉) +- 然后运行 +```bash + npx hardhat compile + ``` +来进行合约编译与部署 +**部署合约到本地网络**: + ```bash + npx hardhat run scripts/deploy.js --network ganache + ``` + 输入上面命令的时候会有如下回复: + Deploying contracts with the account: YOUR_PRIVATE_KEY + SimpleStorage deployed to: YOUR_ADDRESS + 下面那个是连接账户时的地址请填到main.go的大约在75行的YOUR_ADDRESS那儿。 +4. +## Go 应用程序 +Go 应用程序实现了HTTP服务器功能,允许用户通过API接口设置和获取存储于智能合约中的数据。 + +### 运行Go服务 +首先需要加载配置文件(例如:config.json),其中包含私钥等敏感信息。 +然后启动Go HTTP服务器: + +go env -w GOPROXY=https://goproxy.cn,direct +```bash +go run main.go +``` +现在,您可以访问以下API端点: + +- **设置键值对**: + - 方法: `POST /set?key=&value=` + - 示例: `curl "http://localhost:8080/set?key=1&value=HelloWorld"` + +- **读取键对应的值**: + - 方法: `GET /get?key=` + - 示例: `curl "http://localhost:8080/get?key=1"` +- **利用哈希值读取键对应的值**: + - 方法: `GET /get?BytxHash=` + - 示例: `curl "http://localhost:8080/getByTxHash?txHash=YOUR_HSAH" + +请根据实际情况调整上述URL及参数。 -块 \ No newline at end of file