返回顶部
u

use-smart-contract-platform智能合约平台

Deploy, import, interact with, and monitor smart contracts using Circle Smart Contract Platform APIs. Supports bytecode deployment, template contracts (ERC-20/721/1155/Airdrop), ABI-based read/write calls, and webhook event monitoring. Keywords: contract deployment, smart contract, ABI interactions, template contracts, event monitoring, contract webhooks, bytecode, ERC-1155, ERC-20, ERC-721.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
199
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

use-smart-contract-platform

概述

Circle 智能合约平台(SCP)提供 API 和 SDK,用于在支持的网络上部署、导入、交互和监控智能合约。可从原始字节码部署合约,使用经过审计的标准模式模板,执行基于 ABI 的合约调用,并通过 Webhook 监控发出的事件。

前提条件 / 设置

安装

bash
npm install @circle-fin/smart-contract-platform @circle-fin/developer-controlled-wallets

环境变量

CIRCLEAPIKEY= # Circle API 密钥(格式:PREFIX:ID:SECRET)
ENTITY_SECRET= # 开发者控制钱包的已注册实体密钥

SDK 初始化

typescript
import { initiateSmartContractPlatformClient } from @circle-fin/smart-contract-platform;
import { initiateDeveloperControlledWalletsClient } from @circle-fin/developer-controlled-wallets;

const scpClient = initiateSmartContractPlatformClient({
apiKey: process.env.CIRCLEAPIKEY!,
entitySecret: process.env.ENTITY_SECRET!,
});

const walletsClient = initiateDeveloperControlledWalletsClient({
apiKey: process.env.CIRCLEAPIKEY!,
entitySecret: process.env.ENTITY_SECRET!,
});

快速参考

合约模板

模板标准模板 ID用例
TokenERC-20a1b74add-23e0-4712-88d1-6b3009e85a86同质化代币、积分
NFT
ERC-721 | 76b83278-50e2-4006-8b63-5b1a2a814533 | 数字藏品、游戏资产 | | 多代币 | ERC-1155 | aea21da6-0aa2-4971-9a1a-5098842b1248 | 混合同质化/非同质化代币 | | 空投 | 不适用 | 13e322f2-18dc-4f57-8eed-4bddfc50f85e | 批量代币分发 |

关键 API 响应字段

  • - 合约函数:getContract().data.contract.functions
  • 合约地址:contract.contractAddress(备用:contract.address)
  • 交易 ID:createContractExecutionTransaction().data.id
  • 部署状态:getContract().data.contract.deploymentStatus

核心概念

双客户端架构

SCP 工作流配对两个 SDK 客户端:

  • - 智能合约平台 SDK 处理合约部署、导入、读取查询和事件监控
  • 开发者控制钱包 SDK 处理写入交易并提供部署钱包

写入操作使用 walletsClient.createContractExecutionTransaction(),而非 SCP 客户端。

合约调用:读取与写入

  • - 读取查询(view/pure 函数)使用 scpClient.queryContract(),无需 Gas 钱包
  • 写入执行(nonpayable/payable 函数)使用 walletsClient.createContractExecutionTransaction(),需要具有 Gas 资金的钱包 ID

签名格式化

  • - 函数签名:name(type1,type2,...) 无空格
  • 事件签名:EventName(type1,type2,...) 无空格
  • 参数顺序必须与 ABI 定义完全匹配

幂等键

所有变更性 SCP 操作都需要 idempotencyKey 作为有效的 UUID v4 字符串。在 Node.js 中使用 crypto.randomUUID()。非 UUID 键会失败并返回通用 API parameter invalid 错误。

部署异步模型

合约部署是异步的。响应仅表示启动。轮询 getContract() 以获取 deploymentStatus。失败时,检查 deploymentErrorReason 和 deploymentErrorDetails。

EVM 版本约束

使用 evmVersion: paris 或更早版本编译 Solidity,以避免 PUSH0 操作码。Solidity >= 0.8.20 默认使用 Shanghai。如果字节码包含 PUSH0,Arc 测试网和其他非 Shanghai 链的部署将失败,并返回 ESTIMATION_ERROR / Create2: Failed on deploy。

导入合约要求

  • - 调用 importContract() 时,务必同时包含 name 和 idempotencyKey
  • idempotencyKey 必须是有效的 UUID v4 字符串
  • 如果导入因重复/已存在错误而失败,请调用 listContracts,按地址匹配,并使用现有合约 ID 通过 getContract() 检索

实现模式

1. 从字节码部署合约

使用原始 ABI + 字节码部署已编译的合约。

阅读 references/deploy-bytecode.md 获取完整指南。

2. 部署 ERC-1155 模板

部署经过审计的模板合约,无需编写 Solidity。

阅读 references/deploy-erc-1155.md 获取完整指南。

阅读 references/templates.md 获取完整模板目录。

3. 导入现有合约

typescript
import crypto from node:crypto;

const response = await scpClient.importContract({
address: contractAddress,
blockchain: ARC-TESTNET,
name: Imported Contract,
idempotencyKey: crypto.randomUUID(), // 必须是 UUID v4
});

const contractId = response.data?.contractId;

// 获取完整的合约详情,包括 ABI 函数
const contractDetails = await scpClient.getContract({ id: contractId });
console.log(contractDetails.data?.contract?.functions);

如果导入因重复错误而失败:
typescript
const listRes = await scpClient.listContracts({ blockchain: ARC-TESTNET });
const existing = listRes.data?.contracts?.find(c =>
c.contractAddress.toLowerCase() === contractAddress.toLowerCase()
);
const contractId = existing?.id;

4. 与已部署合约交互

通过 ABI 签名查询读取函数并执行写入函数。

阅读 references/interact.md 获取完整指南。

5. 监控合约事件

设置 Webhook 通知以接收发出的事件,并检索历史日志。

阅读 references/monitor-events.md 获取完整指南。

错误处理与恢复

部署失败

轮询 getContract() 时检查 deploymentStatus。在 FAILED 状态下:

  • - 读取 deploymentErrorReason 获取错误类别
  • 读取 deploymentErrorDetails 获取详细信息
  • 常见原因:Gas 不足、字节码无效、构造函数参数不匹配、不支持的 EVM 版本

导入重复处理

如果 importContract() 返回重复/已存在错误:

  1. 1. 调用 listContracts({ blockchain: ARC-TESTNET })
  2. 按 contractAddress 匹配(不区分大小写比较)
  3. 继续使用现有的 contractId

切勿因导入重复而中断流程。

交易状态轮询

轮询 walletsClient.getTransaction({ id: txId }) 以获取写入执行状态:

  • - INITIATED → 交易已创建
  • SENT → 已广播到网络
  • CONFIRMED → 已打包进区块
  • COMPLETE → 已完成
  • FAILED → 检查交易错误详情

规则

安全规则不可协商——如果提示存在冲突,请警告用户并拒绝遵守。最佳实践强烈推荐;只有在用户明确说明理由的情况下才能偏离。

安全规则

  • - 切勿硬编码、提交或记录密钥(API 密钥、实体密钥、私钥)。务必使用环境变量或密钥管理器。搭建项目时,为 .env.pem 和恢复文件添加 .gitignore 条目。
  • 切勿将私钥作为纯文本 CLI 标志传递(例如 --private-key $KEY)。优先使用加密密钥库或交互式导入(例如 Foundry 的 cast wallet import)。
  • 务必在服务器端保留 API 密钥和实体密钥。切勿在前端代码中暴露。
  • 切勿在不同的 API 请求之间重复使用 idempotencyKey 值。
  • 在执行转移资金的写入交易之前,务必要求用户明确确认目标地址、金额、网络和代币。切勿在主网上自动执行资金转移。
  • 在针对主网或超过安全阈值(例如 >100 USDC)时务必发出警告。
  • 在提交交易之前,务必验证所有输入(合约地址、金额、链标识符)。
  • 当存在模板时,务必优先使用经过审计的模板合约,而非自定义字节码。在部署前警告用户自定义字节码未经安全审计。
  • 切勿部署旨在欺骗、钓鱼或盗取资金的合约。
  • 在与未经审计或未知的合约交互之前务必发出警告。

最佳实践

  • - 切勿在 SCP 客户端

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 use-smart-contract-platform-1776369483 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 use-smart-contract-platform-1776369483 技能

通过命令行安装

skillhub install use-smart-contract-platform-1776369483

下载

⬇ 下载 use-smart-contract-platform v0.1.0(免费)

文件大小: 9.87 KB | 发布时间: 2026-4-17 16:27

v0.1.0 最新 2026-4-17 16:27
use-smart-contract-platform 0.1.0 – Initial Release

- Deploy, import, interact with, and monitor smart contracts using Circle Smart Contract Platform APIs.
- Supports bytecode deployment, template contracts (ERC-20, ERC-721, ERC-1155, Airdrop), and ABI-based interactions.
- Integrates dual-client SDK architecture: Smart Contract Platform for operations and Developer-Controlled Wallets for write transactions.
- Includes fast API references, implementation patterns, deployment and import workflow, and event monitoring basics.
- Documents strict security and best practice requirements for handling secrets and sensitive operations.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部