# Contract
# Create Contract
Basically, creating contract is sending a transaction (transaction type = 1) by specifying contract's binary code and parameters. This process has the following steps.
- Call RPC method
contract_createContractToAddress
to generate a new contract address; - Encode constructor's input parameters according to ABI. This can be done by calling method
abi.encodeParameters
provided in vite.js. If the constructor has no input parameter, skip this step; - Generate transaction data. The data content consists of a prefix of 14 byte length (10 byte consensus group id + 1 byte contract type + 1 byte response latency + 1 byte random degree + 1 byte quota multiplier), compiled code and encoded constructor parameters (generated in Step 2).
- Build account block, then call RPC method
ledger_sendRawTransaction
to create contract. Here parametertoAddress
is the contract address generated in Step 1.data
is transaction data created in Step 3. ChooseblockType
= 1, indicating creating contract transaction. Setamount
andtokenId
as the amount of the token that will be transferred to the contract upon creation.fee
is always 10 VITE, which is the cost of creating contract on Vite network.
Tips
Above steps are implemented in method builtinTxBlock.createContract
in vite.js
Parameter description:
- Delegated consensus group id: The response blocks of contract chain are produced by the supernodes of delegated consensus group that the contract has registered for. One available consensus group at the time being is public consensus group, which has id
00000000000000000002
. - Contract type: Using 1 to indicate Solidity++ contract.
- Response latency: The number of snapshot blocks by which request sent to the contract has been confirmed before responding to the specific transaction. The value ranges from 0 to 75. 0 means there is no waiting period and respond block will be produced immediately. If either timestamp, snapshot block height, or random number is used in the contract, the value must be bigger than zero. Generally speaking, larger response latency means slower contract response and response transaction will consume more quota.
- Random degree: The number of snapshot blocks having random seed by which request sent to this contract is confirmed before responding to the specific transaction. Value range is 0-75. 0 indicates that there is no waiting for the request transaction to be included in a snapshot block that contains random number. If any random number related instruction is used in the contract, the value must be above 0. In general, the larger the value, the more secure the random number. This parameter must be no greater than response latency.
- Quota multiplier: This parameter defines x times of quota is consumed for requested transaction when the contract is called. Quota charged on contract response transaction is not affected. The value ranges from 10 to 100, which means 1-10x quota should be consumed. For example, a value of 15 means that the requested transaction to the contract is charged 1.5x quota.
# Call Contract
Calling a smart contract is to send a special transaction to smart contract's address, specifying method name and passed-in parameters.
- Encode method name and passed-in parameter as ABI interface defines. This step can be done by calling
abi.encodeFunctionCall
method in vite.js - Build transaction block and call RPC method
ledger_sendRawTransaction
to send the transaction to contract. HereintoAddress
is the contract address anddata
is transaction data created in Step 1.blockType
is set to 2.amount
andtokenId
stand for the amount of token that are transferred to the contract.fee
is 0, indicating no transaction fee.
Tips
Above steps are implemented in method builtinTxBlock.callContract
in vite.js
# Read States Off-chain
Contract's states can be accessed off-chain through getter
methods. The ABI definition of getter
method and off-chain code are generated when the contract is compiled.
- Encode off-chain method name and passed-in parameter as ABI interface defines. This step can be done by calling
abi.encodeFunctionCall
method in vite.js - Call RPC method
contract_callOffChainMethod
to query contract states
# Call Built-in Contract
Calling built-in contract is to send a special transaction to built-in contract's address, specifying calling method name and passed-in parameters. Vite has provided 3 built-in smart contracts: Quota, Token Issuance and Consensus.
- Encode method name and passed-in parameter as ABI interface defines. This step can be done by calling
abi.encodeFunctionCall
method in vite.js - Build transaction block and call RPC method
ledger_sendRawTransaction
to send the transaction to built-in contract.
Tips
Methods of built-in contracts are provided in builtinTxBlock
in vite.js
# Quota Contract
# Contract Address
vite_0000000000000000000000000000000000000003f6af7459b9
# ABI
Callback methods:
# Stake (Deprecated)
Stake for quota. The minimum staking amount is 134 VITE. Staked tokens can be retrieved after 259,200 snapshot blocks (about 3 days). The locking period will renew if new staking request is submitted for the same beneficiary.
- Parameters:
beneficiary
:string address
Address of staking beneficiary
# StakeForQuota
Stake for quota. The minimum staking amount is 134 VITE. Staked tokens can be retrieved after 259,200 snapshot blocks (about 3 days). Multiple staking records will be generated if staking for the same beneficiary repeatedly. The hash of staking request transaction is used as staking id, which can be used to retrieve staked tokens when locking period expires.
- Parameters:
beneficiary
:string address
Address of staking beneficiary
# CancelStake (Deprecated)
Cancel staking and retrieve staked tokens after the lock period expires. Retrieving a portion of staked tokens is permitted.
- Parameters:
beneficiary
:string address
Address of staking beneficiaryamount
:string bigint
Amount to retrieve. Cannot be less than 134 VITE. The remaining staking amount cannot be less than 134 VITE.
# DelegateStake
Stake for quota via delegation. The minimum staking amount is 134 VITE. Caller of this ABI method should be another contract which stakes on behalf of its users.
- Parameters:
stakeAddress
:string address
Address of original staking accountbeneficiary
:string address
Address of staking beneficiarybid
:uint8
Business id. Staking records from the same original staking address and for the same beneficiary will be categorized into different groups by business id. The locking period of each group will be dependent on the last staking record among the individual business group.stakeHeight
:string uint64
Locking period in terms of number of snapshot blocks. No less than 259,200.
# DelegateStakeCallback
Callback method for delegated staking. Basically, it is the caller contract's responsibility to implement the callback method to do refund(or other logic) upon staking failure.
- Parameters:
stakeAddress
:string address
Address of original staking accountbeneficiary
:string address
Address of staking beneficiarybid
:uint8
Business id. Staking records from the same original staking address and for the same beneficiary will be categorized into different groups by business id. The locking period of each group will be dependent on the last staking record among the individual business group.stakeHeight
:string uint64
Locking period in terms of number of snapshot blocks. No less than 259,200success
:bool
Iffalse
, caller contract should return the relevant VITE tokens to the user
# CancelDelegateStake
Cancel an existing delegated staking and retrieves staked tokens after the lock period expires. However, retrieving a part of staked tokens is also permitted. In that case, the original delegated staking is still valid.
- Parameters:
stakeAddress
:string address
Address of original staking accountbeneficiary
:string address
Address of staking beneficiaryamount
:string bigint
Amount to retrieve. Cannot be less than 134 VITE. The remaining staking amount cannot be less than 134 VITE.bid
:uint8
Business id. Staking records from the same original staking address and for the same beneficiary will be categorized into different groups by business id. The locking period of each group will be dependent on the last staking record among the individual business group.
# CancelDelegateStakeCallback
Callback method for cancelling delegated staking. Basically, it is the caller contract's responsibility to implement the callback method to do refund(or other logic) upon cancellation failure.
- Parameters:
stakeAddress
:string address
Address of original staking accountbeneficiary
:string address
Address of staking beneficiaryamount
:string bigint
Amount to retrieve. Cannot be less than 134 VITE. The remaining staking amount cannot be less than 134 VITE.bid
:uint8
Business id. Staking records from the same original staking address and for the same beneficiary will be categorized into different groups by business id. The locking period of each group will be dependent on the last staking record among the individual business group.success
:bool
Iftrue
, caller contract should return the relevant VITE tokens to the user
# Consensus Contract
# Contract Address
vite_0000000000000000000000000000000000000004d28108e76b
# ABI
# Register
Register a new block producer. This operation requires to stake 1m VITE for a locking period of 7,776,000 snapshot blocks (about 3 months).
- Parameters:
sbpName
:string
The unique name of the block producer. Cannot be modified after the registration.blockProducingAddress
:string address
Block producing address. This is the address that signs the snapshot block. It's highly recommended to use a different address other than the registration address.rewardWithdrawAddress
:string address
Reward withdrawal address.
Tips
Always have your node fully synced before registration.
# UpdateBlockProducingAddress
Update the block producing address for an existing producer
- Parameters:
sbpName
:string
The unique name of the block producerblockProducingAddress
:string address
New block producing address
# UpdateRewardWithdrawAddress
Update reward withdrawal address for an existing producer
- Parameters:
sbpName
:string
The unique name of the block producerrewardWithdrawAddress
:string address
New reward withdrawal address
# Revoke
Cancel a block producer after the locking period has passed. A cancelled producer will stop producing snapshot blocks immediately.
- Parameters:
sbpName
:string
The unique name of the block producer
# WithdrawReward
Withdraw block producing reward. The first 100 block producers in a cycle's last round can withdraw block producing rewards in 1 hour after the cycle is complete.
- Parameters:
sbpName
:string
The unique name of the block producerreceiveAddress
:string address
Address to receive block producing rewards
# Vote
Vote for a block producer. The VITE balance in the account is taken as voting weight. An account can only vote for one SBP at a time.
- Parameters:
sbpName
:string
Distinct name of block producer
# CancelVote
Cancel vote
- Parameters: None
# Token Issuance Contract
# Contract Address
vite_000000000000000000000000000000000000000595292d996d
# ABI
Callback method:
# IssueToken
Issue a new token at a cost of 1,000 VITE. The issuing account will become token's owner and receive an amount of tokens equivalent to initial total supply.
- Parameters:
isReIssuable
:bool
Iftrue
, newly additional tokens can be minted after initial issuancetokenName
:string
Name of token in 1-40 characters, including uppercase/lowercase letters, spaces and underscores. Cannot have consecutive spaces or start/end with spacetokenSymbol
:string
Symbol of token in 1-10 characters, including uppercase/lowercase letters, spaces and underscores. Cannot useVITE
,VCP
orVX
totalSupply
:string bigint
Total supply. Having . For re-issuable token, this is initial total supplydecimals
:uint8
Decimal places. HavingmaxSupply
:string bigint
Maximum supply. Mandatory for re-issuable token. Having . For non-reissuable token, fill in0
isOwnerBurnOnly
:bool
Iftrue
, the token can only burned by owner. Mandatory for re-issuable token. For non-reissuable token, fill infalse
# ReIssue
Mint an amount of additional tokens after initial issuance. For token's owner only
- Parameters:
tokenId
:string tokenId
Token idamount
:string bigint
Issuing amount. Token's total supply will increase accordingly but cannot exceed max supplyreceiveAddress
:string address
Address to receive newly issued tokens
# Burn
Burn an amount of tokens by sending to token issuance contract. For re-issuable token only
# TransferOwnership
Transfer token ownership. For re-issuable token only
- Parameters:
tokenId
:string tokenId
Token idnewOwner
:string address
Address of new owner
# DisableReIssue
Change re-issuable token to non-reissuable. Cannot change back once it is done
- Parameters:
tokenId
:string tokenId
Token id
# GetTokenInformation
Query token info
- Parameters:
tokenId
:string tokenId
Token id
# GetTokenInformationCallback
Callback method for querying token info
- Parameters:
tokenId
:string tokenId
Token idexist
:bool
Iftrue
, the token existstokenSymbol
:string
Symbol of tokenindex
:uint16
Distinct token index beginning from 0 to 999. For tokens having the same symbol, sequential indexes will be allocated according to issuance timeowner
:string address
Address of token's owner
# contract_createContractAddress
Create a new contract address
Parameters:
string address
: Address of creatorstring uint64
: Current height of account chainstring hash
: Hash of previous account block
Returns:
string address
New address
Example:
# contract_getContractInfo
Return contract information by address
Parameters:
string address
: Address of contract
Returns:
ContractInfo
code
:string base64
Code of contractgid
:string gid
Associated consensus group idresponseLatency
:uint8
Response latencyrandomDegree
:uint8
Random degreequotaMultiplier
:uint8
Quota multiplier
Example:
# contract_callOffChainMethod
Call contract's offchain method
Parameters:
Params
:address
:string address
Address of contractcode
:string base64
Binary code for offchain query. This is the value of "OffChain Binary" section generated when compiling the contract with--bin
data
:string base64
Encoded passed-in parameters
Returns:
string base64
Encoded return value. Use decode methods of vitejs to get decoded value
Example:
# contract_getContractStorage
Query contract's state
Parameters:
string address
Address of contractstring
Hex key or prefix of hex key of contract state field
Returns:
map<string,string>
Map of key-value pairs in hex
Example:
# contract_getQuotaByAccount
Return quota balance by account
Parameters:
string address
: Address of account
Returns:
QuotaInfo
currentQuota
:string uint64
Current available quotamaxQuota
:string uint64
Max quota, equivalent to UTPEstakeAmount
:string bigint
Amount of staking
Example:
# contract_getStakeList
Return staking records by account, ordered by target unlocking height in descending order
Parameters:
string address
: Address of staking accountint
: Page index, starting from 0int
: Page size
Returns:
StakeListInfo
totalStakeAmount
:string bigint
The total staking amount of the accounttotalStakeCount
:int
The total number of staking recordsstakeList
:Array<StakeInfo>
Staking record liststakeAddress
:string address
Address of staking accountstakeAmount
:string bigint
Amount of stakingexpirationHeight
:string uint64
Target unlocking heightbeneficiary
:string address
Address of staking beneficiaryexpirationTime
:int64
Estimated target unlocking timeisDelegated
:bool
Iftrue
, this is a delegated staking recorddelegateAddress
:string address
Address of delegate account. For non-delegated staking, 0 is filledbid
:uint8
Business id. For non-delegated staking, 0 is filled
Example:
# contract_getRequiredStakeAmount
Return the minimum required amount of staking in order to obtain the given quota
Parameters:
string uint64
: Quotas accumulated per second. For example, an amount of 21,000 quota are consumed to send a transaction with no comment, in this case, to satisfy the minimum 280 (21000/75) quota accumulation per second in an epoch, a staking amount of 134 VITE is required
Returns:
string bigint
: The minimum amount of staking
Example:
# contract_getDelegatedStakeInfo
Return delegated staking information
Parameters:
Params
stakeAddress
:string address
Address of original staking accountdelegateAddress
:string address
Address of delegate accountbeneficiary
:string address
Address of staking beneficiarybid
:uint8
Business id. Staking records from the same original staking address and for the same beneficiary will be categorized into different groups by business id. The locking period of each group will be dependent on the last staking record among the individual business group.
Returns:
StakeInfo
stakeAddress
:string address
Address of staking accountstakeAmount
:string bigint
Amount of stakingexpirationHeight
:string uint64
Target unlocking heightbeneficiary
:string address
Address of staking beneficiaryexpirationTime
:int64
Estimated target unlocking timeisDelegated
:bool
Iftrue
, this is a delegated staking recorddelegateAddress
:string address
Address of delegate account. For non-delegated staking, 0 is filledbid
:uint8
Business id. For non-delegated staking, 0 is filled
Example:
# contract_getSBPList
Return registered SBP list, including historical SBP nodes, ordered by target unlocking height in descending order
Parameters:
string address
: Address of registration account
Returns:
Array<SBPInfo>
name
:string
Name of SBPblockProducingAddress
:string address
Block producing addressstakeAddress
:string address
Address of registration accountstakeAmount
:string bigint
Amount of stakingexpirationHeight
:string uint64
Target unlocking height. Registered SBP node can be cancelled after the locking period expires.expirationTime
:int64
Estimated target unlocking timerevokeTime
:int64
Time of cancellation. For non-cancelled SBP nodes, 0 is filled
Example:
# contract_getSBPRewardPendingWithdrawal
Return un-retrieved SBP rewards by SBP name
Parameters:
string
: Name of SBP
Returns:
RewardInfo
totalReward
:string bigint
The total rewards that have not been retrievedblockProducingReward
:string bigint
Un-retrieved block creation rewardsvotingReward
:string bigint
Un-retrieved candidate additional rewards(voting rewards)allRewardWithdrawed
:bool
Iftrue
, the SBP node has been cancelled and all rewards have been withdrawn
Example:
# contract_getSBPRewardByTimestamp
Return SBP rewards in 24h by timestamp. Rewards of all SBP nodes in the cycle that the given timestamp belongs will be returned.
Parameters:
int64
: Timestamp in seconds
Returns:
RewardByDayInfo
rewardMap
:map<string,RewardInfo>
totalReward
:string bigint
The total rewards that have not been retrievedblockProducingReward
:string bigint
Un-retrieved block creation rewardsvotingReward
:string bigint
Un-retrieved candidate additional rewards(voting rewards)producedBlocks
:string bigint
Actual blocks producedtargetBlocks
:string bigint
Target blocks should be produced
startTime
:int64
Cycle start timeendTime
:int64
Cycle end timecycle
:string uint64
Index of cycle
Example:
# contract_getSBPRewardByCycle
Return SBP rewards of all SBP nodes by cycle
Parameters:
string uint64
: Index of cycle
Returns:
RewardByDayInfo
rewardMap
:map<string,RewardInfo>
totalReward
:string bigint
The total rewards that have not been retrievedblockProducingReward
:string bigint
Un-retrieved block creation rewardsvotingReward
:string bigint
Un-retrieved candidate additional rewards(voting rewards)producedBlocks
:string bigint
Actual blocks producedtargetBlocks
:string bigint
Target blocks should be produced
startTime
:int64
Cycle start timeendTime
:int64
Cycle end timecycle
:string uint64
Index of cycle
Example:
# contract_getSBP
Return SBP node information
Parameters:
string
: Name of SBP
Returns:
SBPInfo
name
:string
Name of SBPblockProducingAddress
:string address
Block producing addressstakeAddress
:string address
Address of registration accountstakeAmount
:string bigint
Amount of stakingexpirationHeight
:string uint64
Target unlocking height. Registered SBP node can be cancelled after the locking period expires.expirationTime
:int64
Estimated target unlocking timerevokeTime
:int64
Time of cancellation. For non-cancelled SBP nodes, 0 is filled
Example:
# contract_getSBPVoteList
Return current number of votes of all SBP nodes
Parameters:
Returns:
Array<SBPVoteInfo>
sbpName
:string
Name of SBPblockProducingAddress
:string address
Block producing addresssvotes
:string bigint
Number of votes
Example:
# contract_getVotedSBP
Return voting information by account
Parameters:
string address
: Address of voting account
Returns:
VoteInfo
blockProducerName
:string
Name of SBPstatus
:uint8
Status of registration. For cancelled SBP node,2
is filled, otherwise1
for valid SBPsvotes
:string bigint
Number of votes, equivalent to account balance
Example:
# contract_getSBPVoteDetailsByCycle
Return voting details of all SBP nodes by cycle
Parameters:
string uint64
: Index of cycle
Returns:
Array<SBPVoteDetail>
blockProducerName
:string
Name of SBPtotalVotes
:string bigint
The total number of votesblockProducingAddress
:string address
Block producing addresshistoryProducingAddresses
:Array<string address>
Historical block producing address listaddressVoteMap
:map<string address, string bigint>
Voting details
Example:
# contract_getTokenInfoList
Return a list of all tokens issued
Parameters:
int
: Page index, starting from 0int
: Page size
Returns:
TokenListInfo
totalCount
:int
The total number of tokenstokenInfoList
:Array<TokenInfo>
tokenName
:string
Token nametokenSymbol
:string
Token symboltotalSupply
:big.Int
Total supplydecimals
:uint8
Decimal placesowner
:Address
Token ownerisReIssuable
:bool
Whether the token can be re-issuedmaxSupply
:big.Int
Maximum supplyisOwnerBurnOnly
:bool
Whether the token can be burned by the owner onlytokenId
:TokenId
Token IDindex
:uint16
Token index between 0-999. For token having the same symbol, sequential indexes will be allocated according to when the token is issued.
Example:
# contract_getTokenInfoById
Return token information
Parameters:
string tokenId
: Token id
Returns:
TokenInfo
tokenName
:string
Token nametokenSymbol
:string
Token symboltotalSupply
:big.Int
Total supplydecimals
:uint8
Decimal placesowner
:Address
Token ownerisReIssuable
:bool
Whether the token can be re-issuedmaxSupply
:big.Int
Maximum supplyisOwnerBurnOnly
:bool
Whether the token can be burned by the owner onlytokenId
:TokenId
Token IDindex
:uint16
Token index between 0-999. For token having the same symbol, sequential indexes will be allocated according to when the token is issued.
Example:
# contract_getTokenInfoListByOwner
Return a list of tokens issued by the given owner
Parameters:
string address
: Address of token owner
Returns:
Array<TokenInfo>
tokenName
:string
Token nametokenSymbol
:string
Token symboltotalSupply
:big.Int
Total supplydecimals
:uint8
Decimal placesowner
:Address
Token ownerisReIssuable
:bool
Whether the token can be re-issuedmaxSupply
:big.Int
Maximum supplyisOwnerBurnOnly
:bool
Whether the token can be burned by the owner onlytokenId
:TokenId
Token IDindex
:uint16
Token index between 0-999. For token having the same symbol, sequential indexes will be allocated according to when the token is issued.
Example: