Skip to content

Commit 95442be

Browse files
authored
Merge pull request #2 from Esscrypt/feat/v1
Chore: fix jsons
2 parents a718db6 + 288039a commit 95442be

36 files changed

+850
-5226
lines changed

.eliza/registrysettings.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/npm-deploy.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Publish Package
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
verify_version:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
should_publish: ${{ steps.check.outputs.should_publish }}
14+
version: ${{ steps.check.outputs.version }}
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Check if package.json version changed
22+
id: check
23+
run: |
24+
echo "Current branch: ${{ github.ref }}"
25+
26+
# Get current version
27+
CURRENT_VERSION=$(jq -r .version package.json)
28+
echo "Current version: $CURRENT_VERSION"
29+
30+
# Get previous commit hash
31+
git rev-parse HEAD~1 || git rev-parse HEAD
32+
PREV_COMMIT=$(git rev-parse HEAD~1 2>/dev/null || git rev-parse HEAD)
33+
34+
# Check if package.json changed
35+
if git diff --name-only HEAD~1 HEAD | grep "package.json"; then
36+
echo "Package.json was changed in this commit"
37+
38+
# Get previous version if possible
39+
if git show "$PREV_COMMIT:package.json" 2>/dev/null; then
40+
PREV_VERSION=$(git show "$PREV_COMMIT:package.json" | jq -r .version)
41+
echo "Previous version: $PREV_VERSION"
42+
43+
if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
44+
echo "Version changed from $PREV_VERSION to $CURRENT_VERSION"
45+
echo "should_publish=true" >> $GITHUB_OUTPUT
46+
else
47+
echo "Version unchanged"
48+
echo "should_publish=false" >> $GITHUB_OUTPUT
49+
fi
50+
else
51+
echo "First commit with package.json, will publish"
52+
echo "should_publish=true" >> $GITHUB_OUTPUT
53+
fi
54+
else
55+
echo "Package.json not changed in this commit"
56+
echo "should_publish=false" >> $GITHUB_OUTPUT
57+
fi
58+
59+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
60+
61+
publish:
62+
needs: verify_version
63+
if: needs.verify_version.outputs.should_publish == 'true'
64+
runs-on: ubuntu-latest
65+
permissions:
66+
contents: write
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v4
70+
with:
71+
fetch-depth: 0
72+
73+
- name: Create Git tag
74+
run: |
75+
git config user.name "github-actions[bot]"
76+
git config user.email "github-actions[bot]@users.noreply.github.com"
77+
git tag -a "v${{ needs.verify_version.outputs.version }}" -m "Release v${{ needs.verify_version.outputs.version }}"
78+
git push origin "v${{ needs.verify_version.outputs.version }}"
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
82+
- name: Setup Bun
83+
uses: oven-sh/setup-bun@v2
84+
85+
- name: Install dependencies
86+
run: bun install
87+
88+
- name: Build package
89+
run: bun run build
90+
91+
- name: Publish to npm
92+
run: bun publish
93+
env:
94+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
95+
96+
create_release:
97+
needs: [verify_version, publish]
98+
if: needs.verify_version.outputs.should_publish == 'true'
99+
runs-on: ubuntu-latest
100+
permissions:
101+
contents: write
102+
steps:
103+
- name: Create GitHub Release
104+
uses: actions/create-release@v1
105+
env:
106+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
with:
108+
tag_name: "v${{ needs.verify_version.outputs.version }}"
109+
release_name: "v${{ needs.verify_version.outputs.version }}"
110+
body: "Release v${{ needs.verify_version.outputs.version }}"
111+
draft: false
112+
prerelease: false

.github/workflows/test.yml

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,33 @@ name: Lint and Test
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88
workflow_dispatch:
99

1010
jobs:
1111
lint-test:
1212
runs-on: ubuntu-latest
13-
14-
steps:
15-
- uses: actions/checkout@v4
16-
with:
17-
submodules: recursive
1813

19-
- uses: pnpm/action-setup@v4
20-
with:
21-
run_install: |
22-
- recursive: true
23-
args: [--no-frozen-lockfile]
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: recursive
2418

25-
- name: Setup Node.js
26-
uses: actions/setup-node@v4
27-
with:
28-
node-version: '23.3.0'
29-
cache: 'pnpm'
19+
- name: Setup Bun
20+
uses: oven-sh/setup-bun@v1
21+
with:
22+
bun-version: latest
3023

31-
- name: Install dependencies
32-
run: pnpm install
24+
- name: Install dependencies
25+
run: bun install
3326

34-
- name: Run ESLint
35-
run: pnpm run lint
27+
- name: Run ESLint
28+
run: bun run lint
3629

37-
- name: Run Vitest
38-
run: pnpm run test
30+
- name: Run Vitest
31+
run: bun run test
3932

40-
- name: Run Build
41-
run: pnpm run build
33+
- name: Run Build
34+
run: bun run build

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ lib
77

88
.env
99

10-
polkadot_wallet_backups/
10+
polkadot_wallet_backups/
11+
12+
.eliza

.npmignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*
2+
3+
!dist/**
4+
!package.json
5+
!readme.md
6+
!tsup.config.ts
7+
8+
test_wallet_backups/
9+
10+
lib
11+
12+
.env
13+
14+
polkadot_wallet_backups/
15+
16+
.eliza

README.md

Lines changed: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
A plugin for handling Polkadot blockchain operations, providing wallet management and price fetching capabilities.
44

5+
### Usage
6+
---
7+
Add the plugin to your character configuration:
8+
9+
```
10+
"plugins": ["@elizaos-plugins/plugin-polkadot"]
11+
```
12+
## Configuration
13+
The plugin requires these environment variables (can be set in .env file or character settings):
14+
```env
15+
"settings": {
16+
"POLKADOT_RPC_URL": "rpc-url",
17+
"COINMARKETCAP_API_KEY": "<api-key>",
18+
"POLKADOT_PRIVATE_KEY": "<private_key>"
19+
}
20+
```
21+
Or in .env file:
22+
23+
```env
24+
POLKADOT_RPC_URL=your_polkadot_rpc_endpoint # Optional - defaults to wss://rpc.polkadot.io
25+
COINMARKETCAP_API_KEY=your_cmc_api_key # Optional - for fetching token prices
26+
POLKADOT_PRIVATE_KEY=your_mnemonic_phrase # Optional - for default wallet initialization via initWalletProvider
27+
```
28+
529
## Overview
630

731
This plugin provides functionality to:
@@ -23,59 +47,7 @@ This plugin provides functionality to:
2347

2448
### Screenshot
2549

26-
### Quick Start
27-
28-
```bash
29-
# Ensure you have Node.js and pnpm installed
30-
# nvm use 23 && npm install -g pnpm
31-
32-
# Set required environment variables (see Configuration section)
33-
export POLKADOT_RPC_URL="wss://rpc.polkadot.io"
34-
export COINMARKETCAP_API_KEY="your_coinmarketcap_api_key"
35-
# Optional: POLKADOT_PRIVATE_KEY="your_mnemonic_phrase_for_default_wallet_initialization"
36-
37-
# Run the debug script (if available)
38-
# bash ./packages/plugin-polkadot/scripts/debug.sh
39-
```
40-
41-
## Getting Started
42-
43-
### New to ElizaOS
44-
45-
To test this plugin with ElizaOS from scratch, follow these steps:
46-
47-
1. Clone the ElizaOS monorepo: https://github.com/elizaOS/eliza
48-
2. Inside packages, clone the polkadot-plugin repo: https://github.com/Esscrypt/plugin-polkadot
49-
3. Inside the characters folder, link the plugin. example character file: https://gist.github.com/mikirov/74ec0c51255050562b2bdd63ccfc36fb
50-
4. Inside agent folder, add `"@elizaos/plugin-polkadot": "workspace:*"` to the dependencies section in package.json
51-
5. Follow install and build instructions: `pnpm install --no-frozen-lockfile && pnpm build`
52-
6. Start WEB UI: `pnpm start:client`
53-
7. Start Agent: `pnpm start --characters="characters/dobby.character.json"`
54-
8. (Optional) set .env with **POLKADOT_PRIVATE_KEY** and **POLKADOT_RPC_URL**
55-
56-
> Note: When starting the Agent, if **POLKADOT_PRIVATE_KEY** is not set, an error will pop up, but the agent will still run and expect a wallet to get created by the user
57-
58-
9. Go to [http://localhost:5173/](http://localhost:5173/) and interact with the agent.
59-
60-
### Existing ElizaOS Users
61-
62-
```bash
63-
npm install @elizaos/plugin-polkadot
64-
# or
65-
pnpm add @elizaos/plugin-polkadot
66-
```
67-
68-
## Configuration
69-
70-
The plugin requires the following environment variables:
71-
72-
```env
73-
POLKADOT_RPC_URL=your_polkadot_rpc_endpoint # Optional - defaults to wss://rpc.polkadot.io
74-
COINMARKETCAP_API_KEY=your_cmc_api_key # Optional - for fetching token prices
75-
POLKADOT_PRIVATE_KEY=your_mnemonic_phrase # Optional - for default wallet initialization via initWalletProvider
76-
```
77-
78-
## Usage
50+
## Code Usage
7951

8052
Import and register the plugin in your Eliza configuration:
8153

@@ -99,38 +71,38 @@ import { WalletProvider, initWalletProvider, WalletSourceType, type WalletProvid
9971
import type { IAgentRuntime } from "@elizaos/core";
10072

10173
// Initialize the provider (e.g., from environment settings if POLKADOT_PRIVATE_KEY is set)
102-
// const walletProvider = await initWalletProvider(runtime);
74+
const walletProvider = await initWalletProvider(runtime);
10375

10476
// Or create/import a wallet:
10577
// 1. Generate a new wallet and save its encrypted backup
106-
// const { walletProvider, mnemonic, encryptedBackup } = await WalletProvider.generateNew(
107-
// "wss://rpc.polkadot.io",
108-
// "your-strong-password",
109-
// runtime.cacheManager
110-
// );
111-
// console.log("New Mnemonic (SAVE THIS SECURELY!):", mnemonic);
78+
const { walletProvider, mnemonic, encryptedBackup } = await WalletProvider.generateNew(
79+
"wss://rpc.polkadot.io",
80+
"your-strong-password",
81+
runtime.cacheManager
82+
);
83+
console.log("New Mnemonic (SAVE THIS SECURELY!):", mnemonic);
11284

11385
// 2. Import from mnemonic
114-
// const paramsMnemonic: WalletProviderConstructionParams = {
115-
// rpcUrl: "wss://rpc.polkadot.io",
116-
// cacheManager: runtime.cacheManager,
117-
// source: {
118-
// type: WalletSourceType.FROM_MNEMONIC,
119-
// mnemonic: "your twelve or twenty-four word mnemonic phrase",
120-
// }
121-
// };
122-
// const walletFromMnemonic = new WalletProvider(paramsMnemonic);
86+
const paramsMnemonic: WalletProviderConstructionParams = {
87+
rpcUrl: "wss://rpc.polkadot.io",
88+
cacheManager: runtime.cacheManager,
89+
source: {
90+
type: WalletSourceType.FROM_MNEMONIC,
91+
mnemonic: "your twelve or twenty-four word mnemonic phrase",
92+
}
93+
};
94+
const walletFromMnemonic = new WalletProvider(paramsMnemonic);
12395

12496
// Get wallet address
125-
// const address = walletProvider.getAddress();
97+
const address = walletProvider.getAddress();
12698

12799
// Get formatted portfolio (currently uses placeholder balance)
128-
// const portfolio = await walletProvider.getFormattedPortfolio(runtime);
129-
// console.log(portfolio);
100+
const portfolio = await walletProvider.getFormattedPortfolio(runtime);
101+
console.log(portfolio);
130102

131103
// Fetch prices
132-
// const prices = await walletProvider.fetchPrices();
133-
// console.log("Current DOT price:", prices.nativeToken.usd.toString());
104+
const prices = await walletProvider.fetchPrices();
105+
console.log("Current DOT price:", prices.nativeToken.usd.toString());
134106
```
135107

136108
### Create Polkadot Wallet Action
@@ -145,16 +117,16 @@ import { CreateWalletAction } from "@elizaos/plugin-polkadot/src/actions/createW
145117
import type { IAgentRuntime } from "@elizaos/core";
146118

147119
// Assuming 'runtime' is an IAgentRuntime instance
148-
// const rpcUrl = runtime.getSetting("POLKADOT_RPC_URL") || "wss://rpc.polkadot.io";
149-
// const action = new CreateWalletAction(runtime);
120+
const rpcUrl = runtime.getSetting("POLKADOT_RPC_URL") || "wss://rpc.polkadot.io";
121+
const action = new CreateWalletAction(runtime);
150122

151-
// const { walletAddress, mnemonic } = await action.createWallet({
152-
// rpcUrl,
153-
// encryptionPassword: "user-provided-strong-password",
154-
// });
123+
const { walletAddress, mnemonic } = await action.createWallet({
124+
rpcUrl,
125+
encryptionPassword: "user-provided-strong-password",
126+
});
155127

156-
// console.log("Wallet Address:", walletAddress);
157-
// console.log("Mnemonic (store securely!):", mnemonic);
128+
console.log("Wallet Address:", walletAddress);
129+
console.log("Mnemonic (store securely!):", mnemonic);
158130
// A file backup is also created in 'polkadot_wallet_backups' directory.
159131
```
160132

@@ -313,4 +285,4 @@ For more information about Polkadot:
313285

314286
## License
315287

316-
This plugin is part of the Eliza project. See the main project repository for license information.
288+
This plugin is part of the Eliza project. See the main project repository for license information.

0 commit comments

Comments
 (0)