hss-system-contract
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHedera Schedule Service (HSS) System Contract
Hedera Schedule Service (HSS) 系统合约
The Hedera Schedule Service system contract at exposes functions for creating and managing scheduled transactions from within Solidity. It supports:
0x16b- HIP-755: Authorizing and signing schedules from contracts
- HIP-756: Scheduling native HTS token creation (createFungibleToken, createNonFungibleToken, etc.)
- HIP-1215: Generalized scheduled contract calls — schedule arbitrary calls to any contract (or self) for DeFi automation, vesting, DAO operations
地址为 的 Hedera Schedule Service 系统合约提供了在 Solidity 中创建和管理计划交易的函数。它支持:
0x16b- HIP-755:从合约授权和签署计划
- HIP-756:计划原生 HTS 代币创建(createFungibleToken、createNonFungibleToken 等)
- HIP-1215:通用计划合约调用——为 DeFi 自动化、代币释放、DAO 运营计划对任意合约(或自身)的调用
Quick Reference
快速参考
Contract address:
0x16bImports:
solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
import {IHRC1215ScheduleFacade} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/IHRC1215ScheduleFacade.sol";HederaScheduleServiceHederaTokenServiceinternal0x16bHederaResponseCodesResponse codes: SUCCESS = 22 (). See references/api.md for full function list and Hedera response codes.
HederaResponseCodes.SUCCESS合约地址:
0x16b导入:
solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
import {IHRC1215ScheduleFacade} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/IHRC1215ScheduleFacade.sol";HederaScheduleServiceHederaTokenServiceinternal0x16bHederaResponseCodes响应码: SUCCESS = 22()。完整函数列表请参见 references/api.md,Hedera 响应码请参见 Hedera response codes。
HederaResponseCodes.SUCCESSCritical: Inheritance Pattern
关键说明:继承模式
IHederaScheduleServiceIHRC755IHRC756IHRC1215internalHederaScheduleServiceHederaScheduleServicesolidity
contract MyScheduler is HederaScheduleService {
error ScheduleFailed();
function doSchedule() external {
(int64 rc, address scheduleAddr) = scheduleCall(target, expiry, gasLimit, 0, data);
if (rc != HederaResponseCodes.SUCCESS) revert ScheduleFailed();
}
}IHederaScheduleServiceIHRC755IHRC756IHRC1215HederaScheduleServiceinternalHederaScheduleServicesolidity
contract MyScheduler is HederaScheduleService {
error ScheduleFailed();
function doSchedule() external {
(int64 rc, address scheduleAddr) = scheduleCall(target, expiry, gasLimit, 0, data);
if (rc != HederaResponseCodes.SUCCESS) revert ScheduleFailed();
}
}Critical: Non-Reverting Behavior (HIP-1215)
关键说明:非回退行为(HIP-1215)
The , , and functions do not revert. On failure they return . Always check:
scheduleCallscheduleCallWithPayerexecuteCallOnPayerSignature(responseCode, address(0))solidity
error ScheduleFailed();
(int64 rc, address scheduleAddr) = scheduleCall(target, expiry, gasLimit, 0, data);
if (rc != HederaResponseCodes.SUCCESS || scheduleAddr == address(0)) {
revert ScheduleFailed();
}scheduleCallscheduleCallWithPayerexecuteCallOnPayerSignature(responseCode, address(0))solidity
error ScheduleFailed();
(int64 rc, address scheduleAddr) = scheduleCall(target, expiry, gasLimit, 0, data);
if (rc != HederaResponseCodes.SUCCESS || scheduleAddr == address(0)) {
revert ScheduleFailed();
}Capacity and Throttling (HIP-1215)
容量与限流(HIP-1215)
Scheduled calls are throttled per second. Use before scheduling to avoid :
hasScheduleCapacity(expirySecond, gasLimit)SCHEDULE_EXPIRY_IS_BUSYsolidity
bool capacity = hasScheduleCapacity(expirySecond, gasLimit);
if (!capacity) {
// Retry with a later expiry or different gas limit
// See HIP-1215 findAvailableSecond() pattern for exponential backoff + jitter
}计划调用按秒进行限流。在创建计划前使用 检查容量,以避免出现 错误:
hasScheduleCapacity(expirySecond, gasLimit)SCHEDULE_EXPIRY_IS_BUSYsolidity
bool capacity = hasScheduleCapacity(expirySecond, gasLimit);
if (!capacity) {
// Retry with a later expiry or different gas limit
// See HIP-1215 findAvailableSecond() pattern for exponential backoff + jitter
}Common Concepts
通用概念
- Scheduled transaction: Wraps a Hedera transaction (native HTS call or EVM contract call) for deferred execution when signature thresholds are met.
- Payer: Account responsible for paying fees. With , the calling contract is the payer. With
scheduleCall/scheduleCallWithPayer, a separate payer can be specified.executeCallOnPayerSignature - authorizeSchedule: Signs the schedule with the calling contract's key (ContractKey format ).
0.0.<ContractId> - signSchedule: Adds protobuf-encoded signatures from EOAs or other keys.
- Expiration: Schedules that fail to collect all required signatures before are automatically removed from the network.
expirySecond
- Scheduled transaction:包装 Hedera 交易(原生 HTS 调用或 EVM 合约调用),用于在满足签名阈值时延迟执行。
- Payer:负责支付费用的账户。使用 时,调用合约为付款方。使用
scheduleCall/scheduleCallWithPayer时,可以指定独立的付款方。executeCallOnPayerSignature - authorizeSchedule:使用调用合约的密钥(ContractKey 格式为 )签署计划。
0.0.<ContractId> - signSchedule:添加来自 EOA 或其他密钥的 protobuf 编码签名。
- Expiration:未能在 前收集到所有必需签名的计划将自动从网络中移除。
expirySecond
Usage Patterns
使用模式
Schedule Native Token Creation (HIP-756)
计划原生代币创建(HIP-756)
Note: The payer must have sufficient HBAR when the schedule executes (for the token creation fee).
solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
import {IHederaTokenService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol";
contract ScheduledTokenCreator is HederaScheduleService {
error FailToSchedule();
function scheduleTokenCreate(
IHederaTokenService.HederaToken memory token,
int64 initialSupply,
int32 decimals,
address payer
) external returns (address scheduleAddr) {
bytes memory callData = abi.encodeCall(
IHederaTokenService.createFungibleToken,
(token, initialSupply, decimals)
);
int64 rc;
(rc, scheduleAddr) = scheduleNative(
address(0x167), callData, payer
);
if (rc != HederaResponseCodes.SUCCESS) revert FailToSchedule();
}
}注意: 计划执行时,付款方必须持有足够的 HBAR(用于支付代币创建费用)。
solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
import {IHederaTokenService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol";
contract ScheduledTokenCreator is HederaScheduleService {
error FailToSchedule();
function scheduleTokenCreate(
IHederaTokenService.HederaToken memory token,
int64 initialSupply,
int32 decimals,
address payer
) external returns (address scheduleAddr) {
bytes memory callData = abi.encodeCall(
IHederaTokenService.createFungibleToken,
(token, initialSupply, decimals)
);
int64 rc;
(rc, scheduleAddr) = scheduleNative(
address(0x167), callData, payer
);
if (rc != HederaResponseCodes.SUCCESS) revert FailToSchedule();
}
}Schedule Arbitrary Contract Call (HIP-1215)
计划任意合约调用(HIP-1215)
solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
contract Scheduler is HederaScheduleService {
error FailToSchedule();
event ScheduleCreated(address);
function scheduleFutureCall(
address target,
uint256 expirySecond,
uint256 gasLimit,
bytes memory callData
) external returns (address scheduleAddr) {
if (!hasScheduleCapacity(expirySecond, gasLimit)) revert FailToSchedule();
int64 rc;
(rc, scheduleAddr) = scheduleCall(
target,
expirySecond > 0 ? expirySecond : block.timestamp + 5,
gasLimit,
0,
callData
);
if (rc != HederaResponseCodes.SUCCESS) {
revert FailToSchedule();
}
emit ScheduleCreated(scheduleAddr);
}
}solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
contract Scheduler is HederaScheduleService {
error FailToSchedule();
event ScheduleCreated(address);
function scheduleFutureCall(
address target,
uint256 expirySecond,
uint256 gasLimit,
bytes memory callData
) external returns (address scheduleAddr) {
if (!hasScheduleCapacity(expirySecond, gasLimit)) revert FailToSchedule();
int64 rc;
(rc, scheduleAddr) = scheduleCall(
target,
expirySecond > 0 ? expirySecond : block.timestamp + 5,
gasLimit,
0,
callData
);
if (rc != HederaResponseCodes.SUCCESS) {
revert FailToSchedule();
}
emit ScheduleCreated(scheduleAddr);
}
}Contract Signs Schedule (HIP-755)
合约签署计划(HIP-755)
solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
contract ScheduleSigner is HederaScheduleService {
error FailToAuthorize();
error FailToSign();
function signAsContract(address scheduleAddr) external {
int64 rc = authorizeSchedule(scheduleAddr);
if (rc != HederaResponseCodes.SUCCESS) revert FailToAuthorize();
}
function signWithSignatureMap(address scheduleAddr, bytes memory sigMap) external {
int64 rc = signSchedule(scheduleAddr, sigMap);
if (rc != HederaResponseCodes.SUCCESS) revert FailToSign();
}
}solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
contract ScheduleSigner is HederaScheduleService {
error FailToAuthorize();
error FailToSign();
function signAsContract(address scheduleAddr) external {
int64 rc = authorizeSchedule(scheduleAddr);
if (rc != HederaResponseCodes.SUCCESS) revert FailToAuthorize();
}
function signWithSignatureMap(address scheduleAddr, bytes memory sigMap) external {
int64 rc = signSchedule(scheduleAddr, sigMap);
if (rc != HederaResponseCodes.SUCCESS) revert FailToSign();
}
}Delete Schedule
删除计划
solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
import {IHRC1215ScheduleFacade} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/IHRC1215ScheduleFacade.sol";
contract ScheduleManager is HederaScheduleService {
error FailToDeleteSchedule();
// Option 1: Internal helper (inheriting HederaScheduleService)
function deleteScheduleExample(address scheduleAddr) external {
int64 rc = deleteSchedule(scheduleAddr);
if (rc != HederaResponseCodes.SUCCESS) {
revert FailToDeleteSchedule();
}
}
// Option 2: Redirect — call deleteSchedule() on the schedule's address
// (works for contracts and EOAs)
function deleteScheduleProxy(address scheduleAddr) external {
int64 rc = IHRC1215ScheduleFacade(scheduleAddr).deleteSchedule();
if (rc != HederaResponseCodes.SUCCESS) {
revert FailToDeleteSchedule();
}
}
}solidity
import {HederaScheduleService} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/HederaScheduleService.sol";
import {IHRC1215ScheduleFacade} from "@hashgraph/smart-contracts/contracts/system-contracts/hedera-schedule-service/IHRC1215ScheduleFacade.sol";
contract ScheduleManager is HederaScheduleService {
error FailToDeleteSchedule();
// Option 1: Internal helper (inheriting HederaScheduleService)
function deleteScheduleExample(address scheduleAddr) external {
int64 rc = deleteSchedule(scheduleAddr);
if (rc != HederaResponseCodes.SUCCESS) {
revert FailToDeleteSchedule();
}
}
// Option 2: Redirect — call deleteSchedule() on the schedule's address
// (works for contracts and EOAs)
function deleteScheduleProxy(address scheduleAddr) external {
int64 rc = IHRC1215ScheduleFacade(scheduleAddr).deleteSchedule();
if (rc != HederaResponseCodes.SUCCESS) {
revert FailToDeleteSchedule();
}
}
}Costs
费用
- Schedule transaction fees match HAPI ScheduleCreate, with a 20% markup for system contract usage.
- Includes gas, storage, and consensus fees. Expired transactions incur no extra fees beyond initial scheduling/signature costs.
- 计划交易费用与 HAPI ScheduleCreate 一致,使用系统合约需额外支付 20% 溢价。
- 费用包含 gas、存储和共识费用。过期交易除初始计划/签名成本外,不会产生额外费用。
References
参考资料
- API Reference: references/api.md — Full function signatures, selectors, and usage notes
- HIP-755: Schedule Service System Contract
- HIP-756: Contract Scheduled Token Create
- HIP-1215: Generalized Scheduled Contract Calls
- Source: hedera-smart-contracts/hedera-schedule-service
- API 参考:references/api.md — 完整函数签名、选择器和使用说明
- HIP-755:Schedule Service System Contract
- HIP-756:Contract Scheduled Token Create
- HIP-1215:Generalized Scheduled Contract Calls
- 源码:hedera-smart-contracts/hedera-schedule-service