AI agent。动不动就是造小人(小机器人)。既然hive活跃的社区。为什么不能造发帖机器人。接入AI不是很nice。说说干就干。搭建开发环境
nodejs。这个在网上搜就行。npm init -y
dhive包与dotenv本地环境包npm install @hiveio/dhive dotenv
构建文件
hivebot/
├── src/
│ ├── index.js # 应用的入口文件
├── .env # 环境变量文件
├── .gitignore # Git 忽略文件配置
├── package.json # Node.js 项目配置文件
├── package-lock.json # 锁定依赖版本的文件
├── README.md # 项目说明文档
└── node_modules/ # 依赖库目录(由 npm 安装自动生成)
构建账户配置信息
.env文件中,写入用户名与posting_keyPOSTING_KEY="5Kxxxxxxxxxxxxxxxxxxxxxxxxxx"
HIVE_USERNAME="dxxxxxxxxxxxxxxx"
代码
在index.js文件中写入代码
import { Client, PrivateKey } from '@hiveio/dhive';
import dotenv from 'dotenv';
dotenv.config();
const post_key=PrivateKey.fromString(process.env.POSTING_KEY);
const postData = {
author: process.env.HIVE_USERNAME, // 发帖者用户名
title: "Hello world from Hivebot!", // 帖子标题
body: "\n ## Hello World!\n This is an automated **bot** posting test.", // 帖子内容
parent_author: "", // 空字符串表示为新帖
parent_permlink: "hive", // 分类标签,到具体板块
permlink: 'hello-world-from-hivebot', // 帖子的永久链接,需唯一
json_metadata:JSON.stringify( { // Hive 帖子的额外元数据
tags: ["hive", "nodejs", "world","bot","test"], // 帖子的标签,用于分类和搜索
app: "dhive-nodejs-hivebot" // 表示发帖使用的应用程序,通常是客户端的名称
})
};
const client = new Client(["https://api.hive.blog", "https://api.hivekings.com", "https://anyx.io", "https://api.openhive.network"]);
async function createPost(postData) {
try {
// 使用 client.broadcast.comment 进行发帖
const result = await client.broadcast.comment(postData, post_key);
console.log('Post successfully created:', result);
} catch (error) {
console.error('Error creating post:', error);
}
}
createPost(postData);
nodejs命令进行执行node ./src/index.js
hive自动发帖还是很简单的 。本来是想在测试网上面进行测试。但是突然发现没找到什么公开测试网。官网提供的信息都是4年前的。这点还是挺遗憾的。4U 8G内存 500GB硬盘的机器才行。自己手里又没合适机器,只能看以后了。索性就是主网测试了。自己又没多余的账户。只能用本尊上。等以后hive便宜点。再充值一个账户出来。有不有大牛知道什么可用的hive测试网。