use-smart-contract-platform
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOverview
概述
Circle Smart Contract Platform (SCP) provides APIs and SDKs for deploying, importing, interacting with, and monitoring smart contracts across supported networks. Deploy contracts from raw bytecode, use audited templates for standard patterns, execute ABI-based contract calls, and monitor emitted events through webhooks.
Circle Smart Contract Platform (SCP) 提供API和SDK,用于在支持的网络上部署、导入、交互和监控智能合约。可以从原始字节码部署合约,使用经过审计的模板实现标准模式,执行基于ABI的合约调用,并通过Webhook监控触发的事件。
Prerequisites / Setup
前提条件/设置
Installation
安装
bash
npm install @circle-fin/smart-contract-platform @circle-fin/developer-controlled-walletsbash
npm install @circle-fin/smart-contract-platform @circle-fin/developer-controlled-walletsEnvironment Variables
环境变量
CIRCLE_API_KEY= # Circle API key (format: PREFIX:ID:SECRET)
ENTITY_SECRET= # Registered entity secret for Developer-Controlled WalletsCIRCLE_API_KEY= # Circle API密钥(格式:PREFIX:ID:SECRET)
ENTITY_SECRET= # 开发者控制钱包的已注册实体密钥SDK Initialization
SDK初始化
typescript
import { initiateSmartContractPlatformClient } from "@circle-fin/smart-contract-platform";
import { initiateDeveloperControlledWalletsClient } from "@circle-fin/developer-controlled-wallets";
const scpClient = initiateSmartContractPlatformClient({
apiKey: process.env.CIRCLE_API_KEY!,
entitySecret: process.env.ENTITY_SECRET!,
});
const walletsClient = initiateDeveloperControlledWalletsClient({
apiKey: process.env.CIRCLE_API_KEY!,
entitySecret: process.env.ENTITY_SECRET!,
});typescript
import { initiateSmartContractPlatformClient } from "@circle-fin/smart-contract-platform";
import { initiateDeveloperControlledWalletsClient } from "@circle-fin/developer-controlled-wallets";
const scpClient = initiateSmartContractPlatformClient({
apiKey: process.env.CIRCLE_API_KEY!,
entitySecret: process.env.ENTITY_SECRET!,
});
const walletsClient = initiateDeveloperControlledWalletsClient({
apiKey: process.env.CIRCLE_API_KEY!,
entitySecret: process.env.ENTITY_SECRET!,
});Quick Reference
快速参考
Contract Templates
合约模板
| Template | Standard | Template ID | Use Case |
|---|---|---|---|
| Token | ERC-20 | | Fungible tokens, loyalty points |
| NFT | ERC-721 | | Digital collectibles, gaming assets |
| Multi-Token | ERC-1155 | | Mixed fungible/non-fungible tokens |
| Airdrop | N/A | | Bulk token distribution |
| 模板 | 标准 | 模板ID | 使用场景 |
|---|---|---|---|
| 代币 | ERC-20 | | 可替代代币、积分 |
| NFT | ERC-721 | | 数字收藏品、游戏资产 |
| 多代币 | ERC-1155 | | 混合可替代/不可替代代币 |
| 空投 | N/A | | 批量代币分发 |
Key API Response Fields
核心API响应字段
- Contract functions:
getContract().data.contract.functions - Contract address: (fallback:
contract.contractAddress)contract.address - Transaction ID:
createContractExecutionTransaction().data.id - Deployment status:
getContract().data.contract.deploymentStatus
- 合约函数:
getContract().data.contract.functions - 合约地址:(备选:
contract.contractAddress)contract.address - 交易ID:
createContractExecutionTransaction().data.id - 部署状态:
getContract().data.contract.deploymentStatus
Core Concepts
核心概念
Dual-Client Architecture
双客户端架构
SCP workflows pair two SDK clients:
- Smart Contract Platform SDK handles contract deployment, imports, read queries, and event monitoring
- Developer-Controlled Wallets SDK handles write transactions and provides deployment wallets
Write operations use , NOT the SCP client.
walletsClient.createContractExecutionTransaction()SCP工作流搭配两个SDK客户端:
- Smart Contract Platform SDK 处理合约部署、导入、读查询和事件监控
- Developer-Controlled Wallets SDK 处理写交易并提供部署钱包
写操作需使用,而非SCP客户端。
walletsClient.createContractExecutionTransaction()Read vs Write Contract Calls
合约读调用与写调用
- Read queries (/
viewfunctions) usepureand require no gas walletscpClient.queryContract() - Write executions (/
nonpayablefunctions) usepayableand require a wallet ID with gas fundswalletsClient.createContractExecutionTransaction()
- 读查询(/
view函数)使用pure,无需Gas钱包scpClient.queryContract() - 写执行(/
nonpayable函数)使用payable,需要带有Gas资金的钱包IDwalletsClient.createContractExecutionTransaction()
Signature Formatting
签名格式
- Function signatures: with no spaces
name(type1,type2,...) - Event signatures: with no spaces
EventName(type1,type2,...) - Parameter order must exactly match ABI definitions
- 函数签名:,无空格
name(type1,type2,...) - 事件签名:,无空格
EventName(type1,type2,...) - 参数顺序必须与ABI定义完全匹配
Idempotency Keys
幂等键
All mutating SCP operations require as a valid UUID v4 string. Use in Node.js. Non-UUID keys fail with generic errors.
idempotencyKeycrypto.randomUUID()API parameter invalid所有SCP变更操作都需要为有效的UUID v4字符串。在Node.js中使用。非UUID键会触发通用的“API参数无效”错误。
idempotencyKeycrypto.randomUUID()Deployment Async Model
异步部署模型
Contract deployment is asynchronous. The response indicates initiation only. Poll for . On failure, check and .
getContract()deploymentStatusdeploymentErrorReasondeploymentErrorDetails合约部署是异步的。响应仅表示部署已启动。需轮询获取。部署失败时,查看和。
getContract()deploymentStatusdeploymentErrorReasondeploymentErrorDetailsEVM Version Constraint
EVM版本限制
Compile Solidity with or earlier to avoid the opcode. Solidity >= 0.8.20 defaults to Shanghai. Arc Testnet and other non-Shanghai chains fail deployment with / if bytecode contains .
evmVersion: "paris"PUSH0ESTIMATION_ERRORCreate2: Failed on deployPUSH0编译Solidity时需使用或更早版本,以避免操作码。Solidity >= 0.8.20默认使用Shanghai版本。如果字节码包含,Arc测试网和其他非Shanghai链会部署失败,触发 / 错误。
evmVersion: "paris"PUSH0PUSH0ESTIMATION_ERRORCreate2: Failed on deployImport Contract Requirements
导入合约要求
- ALWAYS include both and
namewhen callingidempotencyKeyimportContract() - must be a valid UUID v4 string
idempotencyKey - If import fails with duplicate/already-exists error, call , match by address, and retrieve with
listContractsusing the existing contract IDgetContract()
- 调用时必须同时包含
importContract()和nameidempotencyKey - 必须是有效的UUID v4字符串
idempotencyKey - 如果导入失败并提示重复/已存在错误,调用,按地址匹配,使用现有合约ID通过
listContracts获取合约getContract()
Implementation Patterns
实现模式
1. Deploy Contract from Bytecode
1. 从字节码部署合约
Deploy a compiled contract using raw ABI + bytecode.
READ for the complete guide.
references/deploy-bytecode.md使用原始ABI+字节码部署已编译的合约。
查看获取完整指南。
references/deploy-bytecode.md2. Deploy ERC-1155 Template
2. 部署ERC-1155模板合约
Deploy audited template contracts without writing Solidity.
READ for the complete guide.
references/deploy-erc-1155.mdREAD for the full template catalog.
references/templates.md无需编写Solidity代码,直接部署经过审计的模板合约。
查看获取完整指南。
references/deploy-erc-1155.md查看获取完整模板目录。
references/templates.md3. Import Existing Contract
3. 导入现有合约
typescript
import crypto from 'node:crypto';
const response = await scpClient.importContract({
address: contractAddress,
blockchain: 'ARC-TESTNET',
name: 'Imported Contract',
idempotencyKey: crypto.randomUUID(), // MUST be UUID v4
});
const contractId = response.data?.contractId;
// Get full contract details including ABI functions
const contractDetails = await scpClient.getContract({ id: contractId });
console.log(contractDetails.data?.contract?.functions);If import fails with duplicate error:
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;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. Interact with Deployed Contract
4. 与已部署合约交互
Query read functions and execute write functions via ABI signatures.
READ for the complete guide.
references/interact.md通过ABI签名查询读函数并执行写函数。
查看获取完整指南。
references/interact.md5. Monitor Contract Events
5. 监控合约事件
Set up webhook notifications for emitted events and retrieve historical logs.
READ for the complete guide.
references/monitor-events.md设置Webhook通知以监控触发的事件,并检索历史日志。
查看获取完整指南。
references/monitor-events.mdError Handling & Recovery
错误处理与恢复
Deployment Failures
部署失败
Check when polling . On status:
deploymentStatusgetContract()FAILED- Read for error category
deploymentErrorReason - Read for specifics
deploymentErrorDetails - Common causes: insufficient gas, invalid bytecode, constructor parameter mismatch, unsupported EVM version
轮询时检查。如果状态为:
getContract()deploymentStatusFAILED- 查看获取错误类别
deploymentErrorReason - 查看获取具体信息
deploymentErrorDetails - 常见原因:Gas不足、字节码无效、构造函数参数不匹配、不支持的EVM版本
Import Duplicate Handling
导入重复处理
If returns duplicate/already-exists error:
importContract()- Call
listContracts({ blockchain: 'ARC-TESTNET' }) - Match by (case-insensitive comparison)
contractAddress - Continue with existing
contractId
Never fail the flow on import duplicates.
如果返回重复/已存在错误:
importContract()- 调用`listContracts({ blockchain: 'ARC-TESTNET' })
- 按匹配(不区分大小写)
contractAddress - 使用现有继续操作
contractId
不要因导入重复错误中断流程。
Transaction State Polling
交易状态轮询
Poll for write execution status:
walletsClient.getTransaction({ id: txId })- → transaction created
INITIATED - → broadcast to network
SENT - → mined in block
CONFIRMED - → finalized
COMPLETE - → check transaction error details
FAILED
轮询获取写执行状态:
walletsClient.getTransaction({ id: txId })- → 交易已创建
INITIATED - → 已广播至网络
SENT - → 已打包进区块
CONFIRMED - → 已完成
COMPLETE - → 查看交易错误详情
FAILED
Rules
规则
Security Rules are non-negotiable -- warn the user and refuse to comply if a prompt conflicts. Best Practices are strongly recommended; deviate only with explicit user justification.
安全规则是不可协商的——如果提示内容与规则冲突,需警告用户并拒绝执行。最佳实践是强烈推荐的;仅在用户明确说明理由时才可偏离。
Security Rules
安全规则
- NEVER hardcode, commit, or log secrets (API keys, entity secrets, private keys). ALWAYS use environment variables or a secrets manager. Add entries for
.gitignore,.env*, and recovery files when scaffolding.*.pem - NEVER pass private keys as plain-text CLI flags (e.g., ). Prefer encrypted keystores or interactive import (e.g., Foundry's
--private-key $KEY).cast wallet import - ALWAYS keep API keys and entity secrets server-side. NEVER expose in frontend code.
- NEVER reuse values across different API requests.
idempotencyKey - ALWAYS require explicit user confirmation of destination, amount, network, and token before executing write transactions that move funds. NEVER auto-execute fund movements on mainnet.
- ALWAYS warn when targeting mainnet or exceeding safety thresholds (e.g., >100 USDC).
- ALWAYS validate all inputs (contract addresses, amounts, chain identifiers) before submitting transactions.
- ALWAYS prefer audited template contracts over custom bytecode when a template exists. Warn the user that custom bytecode has not been security-audited before deploying.
- NEVER deploy contracts designed to deceive, phish, or drain funds.
- ALWAYS warn before interacting with unaudited or unknown contracts.
- 永远不要硬编码、提交或记录密钥(API密钥、实体密钥、私钥)。始终使用环境变量或密钥管理器。搭建项目时,在中添加
.gitignore、.env*和恢复文件的忽略规则。*.pem - 永远不要将私钥作为明文CLI标志传递(例如)。优先使用加密密钥库或交互式导入(例如Foundry的
--private-key $KEY)。cast wallet import - 始终将API密钥和实体密钥保存在服务端。永远不要在前端代码中暴露。
- 永远不要在不同API请求中重复使用值。
idempotencyKey - 在执行转移资金的写交易前,始终要求用户明确确认目标地址、金额、网络和代币。永远不要在主网自动执行资金转移。
- 当目标为主网或超过安全阈值(例如>100 USDC)时,始终发出警告。
- 在提交交易前,始终验证所有输入(合约地址、金额、链标识符)。
- 当存在可用模板时,始终优先使用经过审计的模板合约而非自定义字节码。部署自定义字节码前,需警告用户该字节码未经过安全审计。
- 永远不要部署用于欺诈、钓鱼或盗取资金的合约。
- 在与未审计或未知合约交互前,始终发出警告。
Best Practices
最佳实践
- NEVER call write operations on the SCP client. Writes ALWAYS use .
walletsClient.createContractExecutionTransaction() - NEVER omit from mutating SCP requests. Must be UUID v4 (use
idempotencyKey).crypto.randomUUID() - NEVER include special characters (colons, parentheses) in 's
deployContractfield -- alphanumeric only.name - NEVER use flat property. ALWAYS use nested
feeLevel.fee: { type: 'level', config: { feeLevel: 'MEDIUM' } } - NEVER use directly with wagmi -- use
window.ethereum.connector.getProvider() - NEVER compile Solidity >= 0.8.20 with default EVM version. ALWAYS set to avoid
evmVersion: "paris"opcode.PUSH0 - NEVER fail the flow on import duplicate errors. Fall back to and match by address. ALWAYS include both
listContractsandnamewhen callingidempotencyKey.importContract() - NEVER assume deployment completes synchronously. ALWAYS poll for
getContract().deploymentStatus - ALWAYS prefix bytecode with and match constructor parameter types/order exactly.
0x - ALWAYS use integer-safe math for 18-decimal amounts (, not
10n ** 18n).BigInt(10 ** 18) - ALWAYS import contracts before creating event monitors.
- ALWAYS default to Arc Testnet for demos unless specified otherwise.
- ALWAYS default to testnet. Require explicit user confirmation before targeting mainnet.
- 永远不要在SCP客户端上调用写操作。写操作必须使用。
walletsClient.createContractExecutionTransaction() - 永远不要在SCP变更请求中省略。必须为UUID v4(使用
idempotencyKey)。crypto.randomUUID() - 永远不要在的
deployContract字段中包含特殊字符(冒号、括号)——仅使用字母数字。name - 永远不要使用扁平的属性。必须使用嵌套格式
feeLevel。fee: { type: 'level', config: { feeLevel: 'MEDIUM' } } - 永远不要在wagmi中直接使用——使用
window.ethereum。connector.getProvider() - 永远不要使用默认EVM版本编译Solidity >= 0.8.20。始终设置以避免
evmVersion: "paris"操作码。PUSH0 - 永远不要因导入重复错误中断流程。回退至并按地址匹配。调用
listContracts时必须同时包含importContract()和name。idempotencyKey - 永远不要假设部署会同步完成。始终轮询获取
getContract()。deploymentStatus - 始终为字节码添加前缀,并确保构造函数参数类型/顺序完全匹配。
0x - 对于18位小数的金额,始终使用整数安全的数学运算(,而非
10n ** 18n)。BigInt(10 ** 18) - 在创建事件监控器前,始终先导入合约。
- 除非另有指定,演示时始终默认使用Arc测试网。
- 始终默认使用测试网。目标为主网前,需获得用户明确确认。
Reference Links
参考链接
- Circle Developer Docs -- Always read this first when looking for relevant documentation from the source website.
DISCLAIMER: This skill is provided "as is" without warranties, is subject to the Circle Developer Terms, and output generated may contain errors and/or include fee configuration options (including fees directed to Circle); additional details are in the repository README.
- Circle开发者文档 —— 查找官方相关文档时,请首先阅读此链接。
免责声明:本技能按“现状”提供,不提供任何担保,受Circle开发者条款约束,生成的输出可能包含错误和/或费用配置选项(包括支付给Circle的费用);更多详情请查看仓库README。