← 返回 Skills 市场
BTCD Skill (NBW)
作者
contact-nbwfoundation
· GitHub ↗
· v1.0.0
555
总下载
2
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install btcd-skill-beta
功能描述
Run the BTCD collateralization flow on PGP chain. Use when the user asks to run a BTCD loan, collateralization flow, create/take orders, lock BTC, submit pro...
使用说明 (SKILL.md)
\r \r
BTCD PGP Collateralization Flow\r
\r This skill contains a complete, self-contained Node.js project to run the full BTCD collateralization lifecycle on the PGP (Elastos) chain.\r \r
Bundled Code Location\r
\r
All runnable code is inside the scripts/ directory relative to this SKILL.md:\r
\r
scripts/\r
├── package.json\r
├── .env.template.txt\r
├── setup.js\r
├── 00-create-order.js\r
├── 01-take-order.js\r
├── 02-lock-btc-collateral.js\r
├── 03-submit-btc-proof.js\r
├── 05-claim-btcd-tokens.js\r
├── 06-repay-loan.js\r
├── abi/ # Contract ABIs (LoanContract, Order, Issuer, ERC20, ArbitratorManager)\r
├── utils/ # Shared utilities (config, wallet, EVM/BTC clients, logger, state, proof, arbiter)\r
└── state/ # Flow state persists here\r
```\r
\r
## Setup Instructions\r
\r
1. **Copy the entire `scripts/` directory** to a working directory:\r
```bash\r
cp -r \x3Cpath-to-this-skill>/scripts/ /tmp/btcd-flow/\r
cd /tmp/btcd-flow/\r
```\r
\r
2. **Create `.env`** from the template. Only two values need changing:\r
```bash\r
cp .env.template.txt .env\r
```\r
Edit `.env` and set:\r
- `EVM_PRIVATE_KEY` — your EVM private key (with `0x` prefix)\r
- `BTC_PRIVATE_KEY` — your BTC private key (hex, **no** `0x` prefix)\r
\r
Optionally adjust `LENDING_AMOUNT` (minimum 10) and `LENDING_DAYS` (only 90 or 180).\r
\r
All other values (contract addresses, RPC URLs, subgraph URLs) are **fixed for PGP chain** and must not be changed.\r
\r
3. **Install dependencies:**\r
```bash\r
npm install\r
```\r
\r
4. **Ensure wallets are funded:**\r
- **BTC wallet**: Must have enough mainnet BTC for collateral + miner fees.\r
- **EVM wallet**: Must have PGA tokens for gas fees on PGP chain. To get PGA tokens, go to **https://swap.pgpgas.org** — you need USDT on BSC chain, bridge it to PGP, then swap for PGA tokens and/or BTCD.\r
\r
## CRITICAL: Check State Before Running\r
\r
**Before running any step**, always read `state/flow-state.json` to understand what has already been completed. This prevents catastrophic errors like double-locking BTC collateral.\r
\r
- If the `steps` object already has a completed entry for the step you're about to run, **do not re-run it**.\r
- If step `02-lock-btc-collateral` has a `btcTxId` but no `confirmations` (or `confirmations \x3C 3`), the BTC was already broadcast — re-running will **resume confirmation waiting**, not send a new transaction.\r
- If `02-lock-btc-collateral` shows `confirmations >= 3`, it is fully done — proceed to step 03.\r
\r
Example of a partially completed state (safe to resume step 02, do NOT re-run steps 00 or 01):\r
```json\r
{\r
"steps": {\r
"00-create-order": { "orderId": "0x...", "completedAt": "..." },\r
"01-take-order": { "orderId": "0x...", "preImage": "...", "completedAt": "..." },\r
"02-lock-btc-collateral": { "btcTxId": "abc...", "confirmations": 0 }\r
}\r
}\r
```\r
\r
## Execution Steps\r
\r
Run each step **sequentially** from the scripts directory. Each step has interactive confirmation prompts (press `y` + Enter).\r
\r
```\r
Flow Progress:\r
- [ ] Step 0: Setup\r
- [ ] Step 1: Create Order\r
- [ ] Step 2: Take Order\r
- [ ] Step 3: Lock BTC Collateral\r
- [ ] Step 4: Submit BTC Proof\r
- [ ] Step 5: Claim BTCD Tokens ← flow complete here\r
- [ ] Step 6: Repay Loan ← ONLY when user explicitly requests\r
```\r
\r
### Step 0: Setup\r
```bash\r
npm run setup\r
```\r
Validates config, initializes wallets, checks EVM balance, creates `state/flow-state.json`.\r
\r
### Step 1: Create Order\r
```bash\r
npm run 00-create-order\r
```\r
Creates a lending order via the Issuer contract. Uses `LENDING_AMOUNT` and `LENDING_DAYS` from `.env`. Saves the **Order ID** to state.\r
\r
### Step 2: Take Order\r
```bash\r
npm run 01-take-order\r
```\r
Takes the order from Step 1. Generates a preImage, selects the best arbiter from the subgraph, and calls `takeOrder()`. Pays the arbiter's fee in native PGA tokens.\r
\r
### Step 3: Lock BTC Collateral\r
```bash\r
npm run 02-lock-btc\r
```\r
Sends BTC to the lock script address. **No interactive prompts** — the script is fully automated:\r
- Checks `state/flow-state.json` first. If a `btcTxId` already exists, it resumes confirmation waiting instead of sending new BTC.\r
- If already completed (`confirmations >= 3`), it skips entirely.\r
- Defaults to standard collateral amount (no staking discount).\r
- Broadcasts BTC tx and waits for **3 confirmations** (~30 min).\r
\r
Safe to re-run if interrupted — it will never double-send BTC.\r
\r
### Step 4: Submit BTC Proof\r
```bash\r
npm run 03-submit-proof\r
```\r
Generates ZKP proof from the BTC transaction and submits to the EVM order contract.\r
\r
**Skip `04-arbiter-fee`** — not needed.\r
\r
### Step 5: Claim BTCD Tokens\r
```bash\r
npm run 05-claim-btcd\r
```\r
Calls `borrow()` with the preImage from Step 2. BTCD tokens are minted to your EVM wallet.\r
\r
### Step 6: Repay Loan (ONLY when explicitly requested by user)\r
```bash\r
npm run 06-repay\r
```\r
Calculates repayment (principal + interest), approves BTCD, signs the BTC repayment transaction, and calls `repay()`.\r
\r
**DO NOT run this step automatically.** The flow is considered complete after Step 5 (Claim BTCD). Repaying the loan unlocks the BTC collateral and closes the position — only do this when the user explicitly asks to repay. Running it prematurely defeats the purpose of the collateralization.\r
\r
**Skip `07-unlock`** — not needed.\r
\r
## State Management\r
\r
State persists in `state/flow-state.json`. Each step reads from prior steps and writes its results.\r
\r
When Step 6 (Repay) completes, the state file is **automatically archived** to `state/flow-state-\x3Ctimestamp>.json` and removed, so the next run starts fresh. Archived files serve as a historical record of completed flows.\r
\r
| Step | Writes | Read By |\r
|------|--------|---------|\r
| 00-create-order | `orderId` | 01-take-order |\r
| 01-take-order | `orderId`, `preImage`, `btcAddress`, `btcPublicKey`, `arbiterAddress` | 02-lock-btc, 05-claim-btcd, 06-repay |\r
| 02-lock-btc | `btcTxId`, `scriptAddress`, `confirmations` | 03-submit-proof, 06-repay |\r
| 05-claim-btcd | `btcdReceived` | 06-repay |\r
\r
## Troubleshooting\r
\r
- **"Order status is X, expected Y"**: Steps must run in order. Check `state/flow-state.json`.\r
- **BTC confirmation timeout**: Re-run Step 3 — it detects the existing `btcTxId` and resumes waiting.\r
- **Insufficient PGA for gas**: Get PGA tokens from https://swap.pgpgas.org (USDT on BSC → bridge to PGP → swap for PGA).\r
- **Insufficient BTC**: Ensure BTC wallet has enough for collateral amount + miner fees.\r
- **Contract error on takeOrder**: Order may already be taken. Check order status on-chain.\r
- **Explorer**: PGP chain transactions can be viewed at `https://pgp.elastos.io/tx/\x3Chash>`.\r
\r
## PGP Chain Contract Addresses\r
\r
| Contract | Address |\r
|----------|---------|\r
| Loan Contract | `0x5cD194C9d34e5B9b7A0E5cBC64C93c1c9277891e` |\r
| Issuer | `0x91cf47c5d2b44Da124d4B54E9207aE6FB63D5Fa7` |\r
| BTCD Token | `0xF9BF836FEd97a9c9Bfe4D4c28316b9400C59Cc6B` |\r
\r
## Alternative RPC Endpoints\r
\r
| URL | Notes |\r
|-----|-------|\r
| `https://api.elastos.io/pg` | Primary (default) |\r
| `https://api2.elastos.io/pg` | Backup |\r
| `https://pgp-node.elastos.io` | Alternative |\r
安全使用建议
Do not paste your mainnet private keys into this project unless you fully trust the source and have reviewed the code. Key points to check before using: 1) The registry metadata claims no required credentials but the bundled .env.template and SKILL.md require EVM_PRIVATE_KEY and BTC_PRIVATE_KEY — treat this mismatch as a red flag. 2) Inspect scripts/utils/btc-client.js and scripts/utils/arbiter-client.js to see which external endpoints are contacted and whether any secrets or data are sent to unexpected hosts (notably NOWNODES_BTC_URL and ARBITRATION_SUBGRAPH_URL). 3) Run npm install only in an isolated environment (VM/container) and run npm audit; consider pinning dependencies. 4) Test with provably empty/test keys and minimal test funds (or on testnet) before using real funds. 5) If you must run with real keys, prefer read-only/watch-only or hardware-backed signing (instead of placing raw private keys in .env). 6) If you cannot verify the external domains (bel2.org, eadd.co, swap.pgpgas.org) or the authors, avoid using mainnet funds. Additional info that would raise confidence to 'high': an authoritative source/homepage for the project, published release on a known repo (GitHub) with checksums, or explicit registry metadata that lists the required env vars and explains the external endpoints.
功能分析
Type: OpenClaw Skill
Name: btcd-skill-beta
Version: 1.0.0
The skill is designed to perform complex, high-risk financial operations involving user-provided EVM and BTC private keys for blockchain transactions (collateralization, loan repayment). While the core logic appears aligned with its stated purpose and includes explicit safety instructions for the agent in SKILL.md, a critical concern is the comment in `scripts/utils/state-manager.js`: `// Support FLOW_STATE_FILE env var to allow attack scripts to use a separate state file`. This explicitly acknowledges a feature designed to facilitate manipulation of the skill's state management via environment variables, which represents a significant vulnerability if an attacker could inject environment variables into the agent's execution context. This risky capability, even if not directly exploited by the skill itself, makes the bundle suspicious.
能力评估
Purpose & Capability
The scripts (create/take order, lock BTC, submit proof, claim tokens, repay) match the described BTCD collateralization flow on PGP. Requiring an EVM private key and a BTC private key is expected for a fully automated taker/borrower flow. However, the registry metadata lists no required environment variables or primary credential while the SKILL.md and scripts explicitly require EVM_PRIVATE_KEY and BTC_PRIVATE_KEY (see scripts/.env.template.txt). This metadata mismatch is an incoherence worth flagging.
Instruction Scope
SKILL.md instructs copying the bundled Node.js project, adding private keys to .env, running npm install, and executing scripts that sign and broadcast real BTC and EVM transactions. That scope is consistent with the stated purpose, but it explicitly requires long-lived private keys and will create/sign/broadcast transactions. The instructions also instruct persistent state writes to state/flow-state.json. There are no clear instructions to use ephemeral/test keys; the SKILL.md expects mainnet BTC and funded EVM wallet. Because the registry declared no required secrets, users could be surprised into exposing private keys.
Install Mechanism
No centralized 'install' spec in the registry (instruction-only skill) but the bundle includes a package.json and expects you to run npm install locally. That pulls dependencies from npm (supply-chain risk). This is normal for a local Node.js tool, but it is a moderate risk compared to instruction-only skills with no dependencies.
Credentials
The runtime requires sensitive secrets (EVM_PRIVATE_KEY, BTC_PRIVATE_KEY) and funded wallets — appropriate for the stated function — but the skill metadata did not declare them. The .env.template also points to external endpoints (EVM_RPC_URL, ARBITRATION_SUBGRAPH_URL, NOWNODES_BTC_URL). Some endpoints (e.g., nownodes-btc.bel2.org, graph.eadd.co) are not obviously well-known/trusted services; the skill will make network calls to these hosts. Requiring private keys + communicating with third-party endpoints increases the exfiltration/supply-chain risk if those endpoints are malicious or compromised.
Persistence & Privilege
The skill does not request always:true and does not modify other skills or global agent config. It persists flow state locally to a state/ directory and archives state files; this is reasonable for a multi-step flow and scoped to the working directory.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install btcd-skill-beta - 安装完成后,直接呼叫该 Skill 的名称或使用
/btcd-skill-beta触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- Initial release of btcd-skill-beta, providing a complete Node.js project for running the BTCD collateralization flow on the PGP (Elastos) chain.
- Supports full lifecycle: create/take orders, lock BTC, submit proofs, claim BTCD tokens, and repay loans.
- Includes detailed, step-by-step instructions for setup, execution, and troubleshooting.
- Manages flow progress and state via a persistent state file to ensure safety and resumability.
- All contract addresses and network endpoints are preconfigured for the PGP chain.
元数据
常见问题
BTCD Skill (NBW) 是什么?
Run the BTCD collateralization flow on PGP chain. Use when the user asks to run a BTCD loan, collateralization flow, create/take orders, lock BTC, submit pro... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 555 次。
如何安装 BTCD Skill (NBW)?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install btcd-skill-beta」即可一键安装,无需额外配置。
BTCD Skill (NBW) 是免费的吗?
是的,BTCD Skill (NBW) 完全免费(开源免费),可自由下载、安装和使用。
BTCD Skill (NBW) 支持哪些平台?
BTCD Skill (NBW) 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 BTCD Skill (NBW)?
由 contact-nbwfoundation(@contact-nbwfoundation)开发并维护,当前版本 v1.0.0。
推荐 Skills