{
  "schemaVersion": "1.0",
  "item": {
    "slug": "btcd-skill-beta",
    "name": "BTCD Skill (NBW)",
    "source": "tencent",
    "type": "skill",
    "category": "AI 智能",
    "sourceUrl": "https://clawhub.ai/contact-nbwfoundation/btcd-skill-beta",
    "canonicalUrl": "https://clawhub.ai/contact-nbwfoundation/btcd-skill-beta",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadMode": "redirect",
    "downloadUrl": "/downloads/btcd-skill-beta",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=btcd-skill-beta",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "installMethod": "Manual import",
    "extraction": "Extract archive",
    "prerequisites": [
      "OpenClaw"
    ],
    "packageFormat": "ZIP package",
    "includedAssets": [
      "scripts/.env.template.txt",
      "scripts/00-create-order.js",
      "scripts/01-take-order.js",
      "scripts/02-lock-btc-collateral.js",
      "scripts/03-submit-btc-proof.js",
      "scripts/05-claim-btcd-tokens.js"
    ],
    "primaryDoc": "SKILL.md",
    "quickSetup": [
      "Download the package from Yavira.",
      "Extract the archive and review SKILL.md first.",
      "Import or place the package into your OpenClaw setup."
    ],
    "agentAssist": {
      "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
      "steps": [
        "Download the package from Yavira.",
        "Extract it into a folder your agent can access.",
        "Paste one of the prompts below and point your agent at the extracted folder."
      ],
      "prompts": [
        {
          "label": "New install",
          "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
        },
        {
          "label": "Upgrade existing",
          "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
        }
      ]
    },
    "sourceHealth": {
      "source": "tencent",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-04-23T16:43:11.935Z",
      "expiresAt": "2026-04-30T16:43:11.935Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
        "contentDisposition": "attachment; filename=\"4claw-imageboard-1.0.1.zip\"",
        "redirectLocation": null,
        "bodySnippet": null
      },
      "scope": "source",
      "summary": "Source download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this source.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/btcd-skill-beta"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    },
    "downloadPageUrl": "https://openagent3.xyz/downloads/btcd-skill-beta",
    "agentPageUrl": "https://openagent3.xyz/skills/btcd-skill-beta/agent",
    "manifestUrl": "https://openagent3.xyz/skills/btcd-skill-beta/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/btcd-skill-beta/agent.md"
  },
  "agentAssist": {
    "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
    "steps": [
      "Download the package from Yavira.",
      "Extract it into a folder your agent can access.",
      "Paste one of the prompts below and point your agent at the extracted folder."
    ],
    "prompts": [
      {
        "label": "New install",
        "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Tell me what you changed and call out any manual steps you could not complete."
      },
      {
        "label": "Upgrade existing",
        "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Summarize what changed and any follow-up checks I should run."
      }
    ]
  },
  "documentation": {
    "source": "clawhub",
    "primaryDoc": "SKILL.md",
    "sections": [
      {
        "title": "BTCD PGP Collateralization Flow",
        "body": "This skill contains a complete, self-contained Node.js project to run the full BTCD collateralization lifecycle on the PGP (Elastos) chain."
      },
      {
        "title": "Bundled Code Location",
        "body": "All runnable code is inside the scripts/ directory relative to this SKILL.md:\n\nscripts/\n├── package.json\n├── .env.template.txt\n├── setup.js\n├── 00-create-order.js\n├── 01-take-order.js\n├── 02-lock-btc-collateral.js\n├── 03-submit-btc-proof.js\n├── 05-claim-btcd-tokens.js\n├── 06-repay-loan.js\n├── abi/                    # Contract ABIs (LoanContract, Order, Issuer, ERC20, ArbitratorManager)\n├── utils/                  # Shared utilities (config, wallet, EVM/BTC clients, logger, state, proof, arbiter)\n└── state/                  # Flow state persists here"
      },
      {
        "title": "Setup Instructions",
        "body": "Copy the entire scripts/ directory to a working directory:\ncp -r <path-to-this-skill>/scripts/ /tmp/btcd-flow/\ncd /tmp/btcd-flow/\n\n\n\nCreate .env from the template. Only two values need changing:\ncp .env.template.txt .env\n\nEdit .env and set:\n\nEVM_PRIVATE_KEY — your EVM private key (with 0x prefix)\nBTC_PRIVATE_KEY — your BTC private key (hex, no 0x prefix)\n\nOptionally adjust LENDING_AMOUNT (minimum 10) and LENDING_DAYS (only 90 or 180).\nAll other values (contract addresses, RPC URLs, subgraph URLs) are fixed for PGP chain and must not be changed.\n\n\nInstall dependencies:\nnpm install\n\n\n\nEnsure wallets are funded:\n\nBTC wallet: Must have enough mainnet BTC for collateral + miner fees.\nEVM 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."
      },
      {
        "title": "CRITICAL: Check State Before Running",
        "body": "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.\n\nIf the steps object already has a completed entry for the step you're about to run, do not re-run it.\nIf step 02-lock-btc-collateral has a btcTxId but no confirmations (or confirmations < 3), the BTC was already broadcast — re-running will resume confirmation waiting, not send a new transaction.\nIf 02-lock-btc-collateral shows confirmations >= 3, it is fully done — proceed to step 03.\n\nExample of a partially completed state (safe to resume step 02, do NOT re-run steps 00 or 01):\n\n{\n  \"steps\": {\n    \"00-create-order\": { \"orderId\": \"0x...\", \"completedAt\": \"...\" },\n    \"01-take-order\": { \"orderId\": \"0x...\", \"preImage\": \"...\", \"completedAt\": \"...\" },\n    \"02-lock-btc-collateral\": { \"btcTxId\": \"abc...\", \"confirmations\": 0 }\n  }\n}"
      },
      {
        "title": "Execution Steps",
        "body": "Run each step sequentially from the scripts directory. Each step has interactive confirmation prompts (press y + Enter).\n\nFlow Progress:\n- [ ] Step 0: Setup\n- [ ] Step 1: Create Order\n- [ ] Step 2: Take Order\n- [ ] Step 3: Lock BTC Collateral\n- [ ] Step 4: Submit BTC Proof\n- [ ] Step 5: Claim BTCD Tokens  ← flow complete here\n- [ ] Step 6: Repay Loan  ← ONLY when user explicitly requests"
      },
      {
        "title": "Step 0: Setup",
        "body": "npm run setup\n\nValidates config, initializes wallets, checks EVM balance, creates state/flow-state.json."
      },
      {
        "title": "Step 1: Create Order",
        "body": "npm run 00-create-order\n\nCreates a lending order via the Issuer contract. Uses LENDING_AMOUNT and LENDING_DAYS from .env. Saves the Order ID to state."
      },
      {
        "title": "Step 2: Take Order",
        "body": "npm run 01-take-order\n\nTakes 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."
      },
      {
        "title": "Step 3: Lock BTC Collateral",
        "body": "npm run 02-lock-btc\n\nSends BTC to the lock script address. No interactive prompts — the script is fully automated:\n\nChecks state/flow-state.json first. If a btcTxId already exists, it resumes confirmation waiting instead of sending new BTC.\nIf already completed (confirmations >= 3), it skips entirely.\nDefaults to standard collateral amount (no staking discount).\nBroadcasts BTC tx and waits for 3 confirmations (~30 min).\n\nSafe to re-run if interrupted — it will never double-send BTC."
      },
      {
        "title": "Step 4: Submit BTC Proof",
        "body": "npm run 03-submit-proof\n\nGenerates ZKP proof from the BTC transaction and submits to the EVM order contract.\n\nSkip 04-arbiter-fee — not needed."
      },
      {
        "title": "Step 5: Claim BTCD Tokens",
        "body": "npm run 05-claim-btcd\n\nCalls borrow() with the preImage from Step 2. BTCD tokens are minted to your EVM wallet."
      },
      {
        "title": "Step 6: Repay Loan (ONLY when explicitly requested by user)",
        "body": "npm run 06-repay\n\nCalculates repayment (principal + interest), approves BTCD, signs the BTC repayment transaction, and calls repay().\n\nDO 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.\n\nSkip 07-unlock — not needed."
      },
      {
        "title": "State Management",
        "body": "State persists in state/flow-state.json. Each step reads from prior steps and writes its results.\n\nWhen Step 6 (Repay) completes, the state file is automatically archived to state/flow-state-<timestamp>.json and removed, so the next run starts fresh. Archived files serve as a historical record of completed flows.\n\nStepWritesRead By00-create-orderorderId01-take-order01-take-orderorderId, preImage, btcAddress, btcPublicKey, arbiterAddress02-lock-btc, 05-claim-btcd, 06-repay02-lock-btcbtcTxId, scriptAddress, confirmations03-submit-proof, 06-repay05-claim-btcdbtcdReceived06-repay"
      },
      {
        "title": "Troubleshooting",
        "body": "\"Order status is X, expected Y\": Steps must run in order. Check state/flow-state.json.\nBTC confirmation timeout: Re-run Step 3 — it detects the existing btcTxId and resumes waiting.\nInsufficient PGA for gas: Get PGA tokens from https://swap.pgpgas.org (USDT on BSC → bridge to PGP → swap for PGA).\nInsufficient BTC: Ensure BTC wallet has enough for collateral amount + miner fees.\nContract error on takeOrder: Order may already be taken. Check order status on-chain.\nExplorer: PGP chain transactions can be viewed at https://pgp.elastos.io/tx/<hash>."
      },
      {
        "title": "PGP Chain Contract Addresses",
        "body": "ContractAddressLoan Contract0x5cD194C9d34e5B9b7A0E5cBC64C93c1c9277891eIssuer0x91cf47c5d2b44Da124d4B54E9207aE6FB63D5Fa7BTCD Token0xF9BF836FEd97a9c9Bfe4D4c28316b9400C59Cc6B"
      },
      {
        "title": "Alternative RPC Endpoints",
        "body": "URLNoteshttps://api.elastos.io/pgPrimary (default)https://api2.elastos.io/pgBackuphttps://pgp-node.elastos.ioAlternative"
      }
    ],
    "body": "BTCD PGP Collateralization Flow\n\nThis skill contains a complete, self-contained Node.js project to run the full BTCD collateralization lifecycle on the PGP (Elastos) chain.\n\nBundled Code Location\n\nAll runnable code is inside the scripts/ directory relative to this SKILL.md:\n\nscripts/\n├── package.json\n├── .env.template.txt\n├── setup.js\n├── 00-create-order.js\n├── 01-take-order.js\n├── 02-lock-btc-collateral.js\n├── 03-submit-btc-proof.js\n├── 05-claim-btcd-tokens.js\n├── 06-repay-loan.js\n├── abi/                    # Contract ABIs (LoanContract, Order, Issuer, ERC20, ArbitratorManager)\n├── utils/                  # Shared utilities (config, wallet, EVM/BTC clients, logger, state, proof, arbiter)\n└── state/                  # Flow state persists here\n\nSetup Instructions\n\nCopy the entire scripts/ directory to a working directory:\n\ncp -r <path-to-this-skill>/scripts/ /tmp/btcd-flow/\ncd /tmp/btcd-flow/\n\n\nCreate .env from the template. Only two values need changing:\n\ncp .env.template.txt .env\n\n\nEdit .env and set:\n\nEVM_PRIVATE_KEY — your EVM private key (with 0x prefix)\nBTC_PRIVATE_KEY — your BTC private key (hex, no 0x prefix)\n\nOptionally adjust LENDING_AMOUNT (minimum 10) and LENDING_DAYS (only 90 or 180).\n\nAll other values (contract addresses, RPC URLs, subgraph URLs) are fixed for PGP chain and must not be changed.\n\nInstall dependencies:\n\nnpm install\n\n\nEnsure wallets are funded:\n\nBTC wallet: Must have enough mainnet BTC for collateral + miner fees.\nEVM 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.\nCRITICAL: Check State Before Running\n\nBefore 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.\n\nIf the steps object already has a completed entry for the step you're about to run, do not re-run it.\nIf step 02-lock-btc-collateral has a btcTxId but no confirmations (or confirmations < 3), the BTC was already broadcast — re-running will resume confirmation waiting, not send a new transaction.\nIf 02-lock-btc-collateral shows confirmations >= 3, it is fully done — proceed to step 03.\n\nExample of a partially completed state (safe to resume step 02, do NOT re-run steps 00 or 01):\n\n{\n  \"steps\": {\n    \"00-create-order\": { \"orderId\": \"0x...\", \"completedAt\": \"...\" },\n    \"01-take-order\": { \"orderId\": \"0x...\", \"preImage\": \"...\", \"completedAt\": \"...\" },\n    \"02-lock-btc-collateral\": { \"btcTxId\": \"abc...\", \"confirmations\": 0 }\n  }\n}\n\nExecution Steps\n\nRun each step sequentially from the scripts directory. Each step has interactive confirmation prompts (press y + Enter).\n\nFlow Progress:\n- [ ] Step 0: Setup\n- [ ] Step 1: Create Order\n- [ ] Step 2: Take Order\n- [ ] Step 3: Lock BTC Collateral\n- [ ] Step 4: Submit BTC Proof\n- [ ] Step 5: Claim BTCD Tokens  ← flow complete here\n- [ ] Step 6: Repay Loan  ← ONLY when user explicitly requests\n\nStep 0: Setup\nnpm run setup\n\n\nValidates config, initializes wallets, checks EVM balance, creates state/flow-state.json.\n\nStep 1: Create Order\nnpm run 00-create-order\n\n\nCreates a lending order via the Issuer contract. Uses LENDING_AMOUNT and LENDING_DAYS from .env. Saves the Order ID to state.\n\nStep 2: Take Order\nnpm run 01-take-order\n\n\nTakes 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.\n\nStep 3: Lock BTC Collateral\nnpm run 02-lock-btc\n\n\nSends BTC to the lock script address. No interactive prompts — the script is fully automated:\n\nChecks state/flow-state.json first. If a btcTxId already exists, it resumes confirmation waiting instead of sending new BTC.\nIf already completed (confirmations >= 3), it skips entirely.\nDefaults to standard collateral amount (no staking discount).\nBroadcasts BTC tx and waits for 3 confirmations (~30 min).\n\nSafe to re-run if interrupted — it will never double-send BTC.\n\nStep 4: Submit BTC Proof\nnpm run 03-submit-proof\n\n\nGenerates ZKP proof from the BTC transaction and submits to the EVM order contract.\n\nSkip 04-arbiter-fee — not needed.\n\nStep 5: Claim BTCD Tokens\nnpm run 05-claim-btcd\n\n\nCalls borrow() with the preImage from Step 2. BTCD tokens are minted to your EVM wallet.\n\nStep 6: Repay Loan (ONLY when explicitly requested by user)\nnpm run 06-repay\n\n\nCalculates repayment (principal + interest), approves BTCD, signs the BTC repayment transaction, and calls repay().\n\nDO 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.\n\nSkip 07-unlock — not needed.\n\nState Management\n\nState persists in state/flow-state.json. Each step reads from prior steps and writes its results.\n\nWhen Step 6 (Repay) completes, the state file is automatically archived to state/flow-state-<timestamp>.json and removed, so the next run starts fresh. Archived files serve as a historical record of completed flows.\n\nStep\tWrites\tRead By\n00-create-order\torderId\t01-take-order\n01-take-order\torderId, preImage, btcAddress, btcPublicKey, arbiterAddress\t02-lock-btc, 05-claim-btcd, 06-repay\n02-lock-btc\tbtcTxId, scriptAddress, confirmations\t03-submit-proof, 06-repay\n05-claim-btcd\tbtcdReceived\t06-repay\nTroubleshooting\n\"Order status is X, expected Y\": Steps must run in order. Check state/flow-state.json.\nBTC confirmation timeout: Re-run Step 3 — it detects the existing btcTxId and resumes waiting.\nInsufficient PGA for gas: Get PGA tokens from https://swap.pgpgas.org (USDT on BSC → bridge to PGP → swap for PGA).\nInsufficient BTC: Ensure BTC wallet has enough for collateral amount + miner fees.\nContract error on takeOrder: Order may already be taken. Check order status on-chain.\nExplorer: PGP chain transactions can be viewed at https://pgp.elastos.io/tx/<hash>.\nPGP Chain Contract Addresses\nContract\tAddress\nLoan Contract\t0x5cD194C9d34e5B9b7A0E5cBC64C93c1c9277891e\nIssuer\t0x91cf47c5d2b44Da124d4B54E9207aE6FB63D5Fa7\nBTCD Token\t0xF9BF836FEd97a9c9Bfe4D4c28316b9400C59Cc6B\nAlternative RPC Endpoints\nURL\tNotes\nhttps://api.elastos.io/pg\tPrimary (default)\nhttps://api2.elastos.io/pg\tBackup\nhttps://pgp-node.elastos.io\tAlternative"
  },
  "trust": {
    "sourceLabel": "tencent",
    "provenanceUrl": "https://clawhub.ai/contact-nbwfoundation/btcd-skill-beta",
    "publisherUrl": "https://clawhub.ai/contact-nbwfoundation/btcd-skill-beta",
    "owner": "contact-nbwfoundation",
    "version": "1.0.0",
    "license": null,
    "verificationStatus": "Indexed source record"
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/btcd-skill-beta",
    "downloadUrl": "https://openagent3.xyz/downloads/btcd-skill-beta",
    "agentUrl": "https://openagent3.xyz/skills/btcd-skill-beta/agent",
    "manifestUrl": "https://openagent3.xyz/skills/btcd-skill-beta/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/btcd-skill-beta/agent.md"
  }
}