Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new plugin hive #2390

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,13 @@ FLOW_PRIVATE_KEY= # Private key for SHA3-256 + P256 ECDSA
FLOW_NETWORK= # Default: mainnet
FLOW_ENDPOINT_URL= # Default: https://mainnet.onflow.org

# Hive Blockchain Configuration
HIVE_ACCOUNT=
HIVE_POSTING_KEY=
HIVE_ACTIVE_KEY=
HIVE_NETWORK=mainnet
HIVE_API_NODE=https://api.hive.blog

# ICP
INTERNET_COMPUTER_PRIVATE_KEY=
INTERNET_COMPUTER_ADDRESS=
Expand Down
2 changes: 1 addition & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"name": "@elizaos/agent",
"version": "0.1.9-alpha.1",
"main": "src/index.ts",
Expand Down Expand Up @@ -56,6 +55,7 @@
"@elizaos/plugin-gitcoin-passport": "workspace:*",
"@elizaos/plugin-goat": "workspace:*",
"@elizaos/plugin-lensNetwork": "workspace:*",
"@elizaos/plugin-hive": "workspace:*",
"@elizaos/plugin-icp": "workspace:*",
"@elizaos/plugin-image-generation": "workspace:*",
"@elizaos/plugin-movement": "workspace:*",
Expand Down
6 changes: 6 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { genLayerPlugin } from "@elizaos/plugin-genlayer";
import { gitcoinPassportPlugin } from "@elizaos/plugin-gitcoin-passport";
import { hivePlugin } from "@elizaos/plugin-hive";
import { imageGenerationPlugin } from "@elizaos/plugin-image-generation";
import { lensPlugin } from "@elizaos/plugin-lensNetwork";
import { multiversxPlugin } from "@elizaos/plugin-multiversx";
Expand Down Expand Up @@ -1010,6 +1011,11 @@ export async function createAgent(
getSecret(character, "FLOW_PRIVATE_KEY")
? flowPlugin
: null,
getSecret(character, "HIVE_ACCOUNT") &&
getSecret(character, "HIVE_POSTING_KEY") &&
getSecret(character, "HIVE_ACTIVE_KEY")
? hivePlugin
: null,
getSecret(character, "LENS_ADDRESS") &&
getSecret(character, "LENS_PRIVATE_KEY")
? lensPlugin
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-hive/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
250 changes: 250 additions & 0 deletions packages/plugin-hive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
# @elizaos/plugin-hive

Core Hive blockchain plugin for Eliza OS that provides essential services and actions for token operations, content interactions, and wallet management.

## Overview

This plugin provides comprehensive functionality to interact with the Hive blockchain, including:

- HIVE/HBD token transfers and management
- Content creation and curation
- Account operations and wallet management
- Market operations and order management
- Following/follower relationship management
- Witness operations
- Blockchain data querying

## Installation

```bash
pnpm install @elizaos/plugin-hive
```

## Configuration

The plugin requires the following environment variables:

```env
HIVE_ACCOUNT=your_hive_account
HIVE_POSTING_KEY=your_posting_key
HIVE_ACTIVE_KEY=your_active_key
HIVE_NETWORK=mainnet|testnet
HIVE_API_NODE=https://api.hive.blog
```

## Usage

Import and register the plugin in your Eliza configuration:

```typescript
import { hivePlugin } from "@elizaos/plugin-hive";

export default {
plugins: [hivePlugin],
// ... other configuration
};
```

### Key Features

#### Token Operations

```typescript
// Send HIVE tokens
const result = await eliza.execute({
action: "SEND_HIVE",
content: {
to: "recipient",
amount: "1.000 HIVE",
memo: "Payment for services",
},
});

// Convert HIVE to HBD
const result = await eliza.execute({
action: "CONVERT_HIVE",
content: {
amount: "100.000 HIVE",
},
});
```

#### Content Management

```typescript
// Create a post
const result = await eliza.execute({
action: "CREATE_POST",
content: {
title: "My First Post",
body: "This is the content of my post",
tags: ["hive", "blog", "introduction"],
},
});

// Vote on content
const result = await eliza.execute({
action: "VOTE",
content: {
author: "username",
permlink: "post-permlink",
weight: 10000, // 100% upvote
},
});
```

## API Reference

### Actions

#### `SEND_HIVE`

Transfers HIVE tokens to another account.

```typescript
{
action: 'SEND_HIVE',
content: {
to: string, // Recipient's Hive account
amount: string, // Amount with currency (e.g., "1.000 HIVE")
memo?: string // Optional memo
}
}
```

#### `SEND_HBD`

Transfers HBD tokens to another account.

```typescript
{
action: 'SEND_HBD',
content: {
to: string,
amount: string, // Amount with currency (e.g., "1.000 HBD")
memo?: string
}
}
```

#### `CREATE_POST`

Creates a new post on the Hive blockchain.

```typescript
{
action: 'CREATE_POST',
content: {
title: string,
body: string,
tags: string[],
beneficiaries?: Array<{
account: string,
weight: number
}>
}
}
```

### Providers

#### Wallet Provider

Provides wallet information and portfolio tracking.

```typescript
const walletInfo = await eliza.getProvider("wallet");
// Returns:
// - Account balance
// - Token balances (HIVE, HBD)
// - Estimated account value
// - Reward balance
```

#### Content Provider

Manages content-related operations.

```typescript
const contentInfo = await eliza.getProvider("content");
// Returns:
// - User's posts
// - Feed content
// - Trending posts
// - Recent posts
```

## Development

### Building

```bash
pnpm run build
```

### Testing

```bash
pnpm test
```

## Security Best Practices

1. **Key Management**

- Store private keys securely
- Use environment variables
- Never expose keys in code
- Implement key rotation

2. **Transaction Safety**

- Validate all inputs
- Implement amount limits
- Double-check recipients
- Monitor transaction status

3. **Content Safety**
- Validate post content
- Check for spam patterns
- Implement content filters
- Monitor for abuse

## Error Handling

The plugin implements comprehensive error handling for:

- Network connectivity issues
- Transaction failures
- Invalid inputs
- Rate limiting
- API node failures
- Authorization errors

## Dependencies

- `@hiveio/dhive`: Core Hive blockchain interaction library
- `bignumber.js`: Precise number handling
- `node-cache`: Caching implementation

## Contributing

Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for details.

## Credits

This plugin integrates with:

- [Hive Blockchain](https://hive.io/)
- [DHive](https://github.com/openhive-network/dhive)
- The Hive Developer Community

Special thanks to:

- The Hive core development team
- The Hive community
- All contributors to this plugin

## License

This plugin is part of the Eliza project. See the main project repository for license information.
3 changes: 3 additions & 0 deletions packages/plugin-hive/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [...eslintGlobalConfig];
40 changes: 40 additions & 0 deletions packages/plugin-hive/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@elizaos/plugin-hive",
"version": "0.1.0",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@hiveio/dhive": "^1.2.7",
"bignumber.js": "^9.1.2",
"node-cache": "^5.1.2"
},
"devDependencies": {
"tsup": "8.3.5",
"@types/node": "^20.0.0",
"@types/node-cache": "^4.2.5",
"typescript": "^5.0.0",
"jest": "^29.0.0",
"@types/jest": "^29.0.0",
"ts-jest": "^29.0.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache .",
"test": "jest",
"test:watch": "jest --watch",
"prepublishOnly": "pnpm run build"
},
"keywords": [
"hive",
"blockchain",
"cryptocurrency",
"social",
"elizaos",
"plugin"
],
"author": "@helo",
"license": "MIT"
}
Loading
Loading