22
33A 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
731This 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
8052Import and register the plugin in your Eliza configuration:
8153
@@ -99,38 +71,38 @@ import { WalletProvider, initWalletProvider, WalletSourceType, type WalletProvid
9971import 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
145117import 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