Skip to main content

Precompiled Smart Contracts

ZenChain supports precompiled smart contracts to improve the user experience. Precompiles work just like other smart contracts deployed on the network, yet are more computationally efficient than user-deployed smart contracts.

info

All of ZenChain's precompiles can be called directly from an externally owned account (EOA). We have temporarily blocked calls to ZenChain's precompiled smart contracts from other smart contracts.

ContractEthereum AddressSolidity InterfaceDescription
NativeStaking0x0000000000000000000000000000000000000800GitHubZenChain staking
NativeFastUnstake0x0000000000000000000000000000000000000801GitHubFast unstake
KeyManager0x0000000000000000000000000000000000000802GitHubManage validator session keys
Batch0x0000000000000000000000000000000000000808GitHubEfficient batch transactions

NativeStaking Precompile

This contract provides comprehensive staking functionality, including core staking operations and various view functions for querying system state and parameters.

Write Functions

FunctionDescription
bondWithRewardDestination(value, dest)Stake tokens and set reward destination.
bondWithPayeeAddress(value, payee)Stake tokens and set a custom payee address for rewards.
bondExtra(value)Add more tokens to your existing stake.
rebond(value)Re-stake a portion of your unbonding tokens.
unbond(value)Schedule a portion of your staked tokens for unbonding.
withdrawUnbonded(numSlashingSpans)Withdraw your unbonded tokens after the unbonding period.
validate(commission, blocked)Declare intent to become a validator with specified commission and blocking status.
nominate(targets)As a nominator, select the validators you want to back.
chill()Stop validating or nominating.
setPayee(payee)Set a custom address to receive rewards.
setRewardDestination(dest)Set the reward destination (Staked, Stash, or None).
payoutStakersByPage(validatorStash, era, page)Trigger payout of rewards for a specific validator, era, and page of nominators.
kick(nominators)Kick specified nominators from a validator's list.
chillOther(stash)Chill another stash account.
forceApplyMinCommission(validatorStash)Force a validator to apply the minimum commission.

View Functions

FunctionDescription
idealValidatorCount()Get the ideal number of validators.
minValidatorCount()Get the minimum number of validators.
invulnerables()Get the list of invulnerable validators.
minNominatorBond()Get the minimum bond amount for nominators.
minValidatorBond()Get the minimum bond amount for validators.
minActiveStake()Get the minimum active nominator stake from the last election.
minValidatorCommissionPerbill()Get the minimum validator commission.
payee(who)Get the reward payee address for an account.
rewardDestination(who)Get the reward destination for an account.
validatorPrefs(who)Get validator preferences (commission and blocked status).
maxValidatorsCount()Get the maximum number of validators.
nominatorPrefs(who)Get nominator preferences (targets, submission era, and suppressed status).
maxNominatorsCount()Get the maximum number of nominators.
currentEra()Get the current era index.
activeEra()Get the active era index.
erasStartSessionIndex(eraIndex)Get the starting session index for a given era.
erasValidatorTotalStake(eraIndex, validatorStash)Get total and own stake for a validator in a given era.
erasValidatorNominatorsCount(eraIndex, validatorStash)Get nominator count and page count for a validator in a given era.
erasValidatorNominationPageTotalExposure(eraIndex, validatorStash, pageIndex)Get total exposure for a specific page of nominators.
erasValidatorNominationPageNominatorExposure(eraIndex, validatorStash, pageIndex, nominationIndex)Get stake and address for a specific nominator.
erasClaimedRewards(eraIndex, validatorStash, index)Get claimed page index for rewards in a specific era.
erasValidatorPrefs(eraIndex, validatorStash)Get validator preferences for a given era.
erasValidatorPayout(eraIndex)Get total validator payout for a given era.
erasTotalRewardPoints(eraIndex)Get total reward points for a given era.
erasValidatorRewardPoints(eraIndex, validatorStash)Get reward points for a validator in a given era.
erasTotalStake(eraIndex)Get total stake for a given era.
maxStakedRewardsPercent()Get maximum staked rewards percentage.
slashRewardFractionPerbill()Get slash reward fraction.
cancelledSlashPayout()Get cancelled slash payout amount.
currentPlannedSession()Get the last planned session index.
isUnbonding(who)Check if an account is unbonding.
status(who)Get the staking status of an account.
stake(who)Get the total and active stake of an account.
isExposedInEra(who, era)Check if an account was exposed in a specific era.
bonded(who)Check if an account is bonded.

Constants

FunctionDescription
historyDepth()Get the number of eras stored in history.
sessionsPerEra()Get the number of sessions per era.
bondingDuration()Get the number of eras a staker's funds remain locked after unbonding request.
slashDeferDuration()Get the number of eras that slashes are deferred.
maxExposurePageSize()Get the maximum size of each ExposurePage.
maxUnlockingChunks()Get the maximum number of unlocking chunks a StakingLedger can have.

This updated documentation now includes all the view functions and constants from the provided Solidity interface, offering a comprehensive overview of the NativeStaking precompile's capabilities.

NativeFastUnstake Precompile

This contract allows for quicker unbonding of your stake under the condition that the staker is not an active validator or nominating another account. If the staker's bond is locked in an ongoing era, it cannot be quickly unbonded because it must remain subject to rewards and slashing.

FunctionDescription
registerFastUnstake()Initiate a fast unstake request.
deregister()Cancel a fast unstake request and return to regular unbonding.

KeyManager Precompile

The KeyManager contract facilitates session key management for validators.

FunctionDescription
setKeys(bytes calldata keys)Sets the session keys of the function caller to the provided keys. This allows an account to set its session keys prior to becoming a validator, and takes effect in the next session. Validators can be obtain keys from their node using the author_rotateKeys RPC method.
purgeKeys()Removes any session keys associated with the function caller. This change will take effect in the next session.
keyOwner(KeyType keyType, bytes32 key)Queries the owner of a specific session key. It returns the address of the key owner, or the zero address if no owner is found.

Batch Precompile

The Batch precompile contract provides methods for efficient batch transactions.

FunctionDescription
batchSome(address[] memory to, uint256[] memory value, bytes[] memory callData, uint64[] memory gasLimit)Batches multiple calls into a single transaction, attempting all subcalls even if one or more revert.
batchSomeUntilFailure(address[] memory to, uint256[] memory value, bytes[] memory callData, uint64[] memory gasLimit)Batches multiple calls into a single transaction. If a subcall reverts, no further subcalls are executed, but the transaction itself succeeds.
batchAll(address[] memory to, uint256[] memory value, bytes[] memory callData, uint64[] memory gasLimit)Batches multiple calls into a single transaction. If any subcall reverts, the entire batch transaction reverts.