hss-system-contract

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hedera Schedule Service (HSS) System Contract

Hedera Schedule Service (HSS) 系统合约

The Hedera Schedule Service system contract at
0x16b
exposes functions for creating and managing scheduled transactions from within Solidity. It supports:
  • 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
地址为
0x16b
的 Hedera Schedule Service 系统合约提供了在 Solidity 中创建和管理计划交易的函数。它支持:
  • HIP-755:从合约授权和签署计划
  • HIP-756:计划原生 HTS 代币创建(createFungibleToken、createNonFungibleToken 等)
  • HIP-1215:通用计划合约调用——为 DeFi 自动化、代币释放、DAO 运营计划对任意合约(或自身)的调用

Quick Reference

快速参考

Contract address:
0x16b
Imports:
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";
HederaScheduleService
is an abstract contract (like
HederaTokenService
for HTS). Inherit it to get
internal
helper functions that handle the low-level calls to
0x16b
.
HederaResponseCodes
is available transitively.
Response codes: SUCCESS = 22 (
HederaResponseCodes.SUCCESS
). See references/api.md for full function list and Hedera response codes.
合约地址:
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";
HederaScheduleService
是一个抽象合约(类似于 HTS 的
HederaTokenService
)。继承它即可获得
internal
辅助函数,用于处理对
0x16b
的底层调用。
HederaResponseCodes
可通过传递依赖获取。
响应码: SUCCESS = 22(
HederaResponseCodes.SUCCESS
)。完整函数列表请参见 references/api.md,Hedera 响应码请参见 Hedera response codes。

Critical: Inheritance Pattern

关键说明:继承模式

IHederaScheduleService
is an empty interface.
Functions are defined in
IHRC755
,
IHRC756
,
IHRC1215
and wrapped as
internal
helpers in
HederaScheduleService
. Your contract must inherit
HederaScheduleService
:
solidity
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();
    }
}
IHederaScheduleService
是一个空接口。
函数定义在
IHRC755
、
IHRC756
、
IHRC1215
中,并在
HederaScheduleService
中封装为
internal
辅助函数。你的合约必须继承
HederaScheduleService
:
solidity
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
scheduleCall
,
scheduleCallWithPayer
, and
executeCallOnPayerSignature
functions do not revert. On failure they return
(responseCode, address(0))
. Always check:
solidity
error ScheduleFailed();

(int64 rc, address scheduleAddr) = scheduleCall(target, expiry, gasLimit, 0, data);
if (rc != HederaResponseCodes.SUCCESS || scheduleAddr == address(0)) {
    revert ScheduleFailed();
}
scheduleCall
、
scheduleCallWithPayer
和
executeCallOnPayerSignature
函数不会回退。失败时它们会返回
(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
hasScheduleCapacity(expirySecond, gasLimit)
before scheduling to avoid
SCHEDULE_EXPIRY_IS_BUSY
:
solidity
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_BUSY
错误:
solidity
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
    scheduleCall
    , the calling contract is the payer. With
    scheduleCallWithPayer
    /
    executeCallOnPayerSignature
    , a separate payer can be specified.
  • 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
    expirySecond
    are automatically removed from the network.
  • 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

参考资料