Contract API
Tip
To enable the Contract RPC API on the node, add the "contract" namespace in "PublicModules" in node_config.json
contract_createContractAddress
Create a new contract address
-
Parameters:
address:addressAccount addressheight:uint64 stringHeight of the account blockpreviousHash:hashHash of the previous account block
-
Returns:
addressNew contract address
Example
contract_getContractInfo
Get contract information by address
-
Parameters:
address:addressAddress of the contract
-
Returns:
ContractInfocode:base64Binary code of the contractgid:gidConsensus group id. Default is00000000000000000002responseLatency:uint8Response latencyrandomDegree:uint8Random degreequotaMultiplier:uint8Quota multiplier
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"code": "AWCAYEBSYAQ2EGEAQVdgADV8AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACQBGP/////FoBjkabLSxRhAEZXW2AAgP1bYQCJYASANgNgIIEQFWEAXFdgAID9W4EBkICANXT///////////////////////////8WkGAgAZCSkZBQUFBhAItWWwBbgHT///////////////////////////8WRmn/////////////FjRgQFFgQFGAggOQg4WH8VBQUFCAdP///////////////////////////xZ/qmUoH130tL08cfK6JZBbkHIF/OCAmoFu+OBLTUlqhbs0YEBRgIKBUmAgAZFQUGBAUYCRA5CiUFb+oWVienpyMFgg5BEYZploBADsJutGp1y0+UwegyI5VjOkuA+v2lg7JFoAKQ==",
"gid": "00000000000000000002",
"responseLatency": 2,
"randomDegree": 1,
"quotaMultiplier": 10
}
}
contract_callOffChainMethod
Call an offchain method in Solidity++ 0.4
-
Parameters:
CallOffChainMethodParamaddress:addressContract addresscode:base64Binary code of the offchain methoddata:base64Encoded arguments
-
Returns:
base64Encoded calling result in base64 format
Note: Offchain method has been replaced by view functions in Solidity++ 0.8
Example
{
"jsonrpc": "2.0",
"id": 1,
"method": "contract_callOffChainMethod",
"params": [{
"address": "vite_22f4f195b6b0f899ea263241a377dbcb86befb8075f93eeac8",
"code": "YIBgQFJgBDYQYEJXYAA1fAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkARj/////xaAY8GjSGUUYERXYEJWWwBbYEpgYFZbYEBRgIKBUmAgAZFQUGBAUYCRA5DzW2AAYABgAFBUkFBgblZbkFb+oWVienpyMFggSaCBXUGf/Mh5lfHDLvGQt9g3K+aLjE2PrRxcLb6RSWQAKQ==",
"data": "waNIZQ=="
}]
}
contract_query
Call a view function in Solidity++ 0.8
-
Parameters:
QueryParamaddress:addressContract addressdata:base64Encoded arguments
-
Returns:
base64Encoded calling result in base64 string
Example
contract_getContractStorage
Query for a contract's states by search key
-
Parameters:
addr:addressAddress of the contractprefix:hexSearch key or prefix of the search key of the state. An empty string means to fetch all states.
-
Returns:
map<hex, hex>Map of key-state in hex format
Example
{
"jsonrpc": "2.0",
"id": 0,
"result": {
"ffe6859e4c369fdb232c625fc49ab073dc558f710b2b46f15e2387418b70b2c5": "10a160f67e2e49af69dbe44e1836a68eaf63942000",
"ffe6859e4c369fdb232c625fc49ab073dc558f710b2b46f15e2387418b70b2c6": "057dc3fa",
"ffe6859e4c369fdb232c625fc49ab073dc558f710b2b46f15e2387418b70b2c7": "021e19e0c9bab2400000"
}
}
contract_getQuotaByAccount
Get the quota of an account. The returned result is in raw quota.
-
Parameters:
addr:addressAddress of the account
-
Returns:
QuotaInfocurrentQuota:uint64 stringAccount's available quotamaxQuota:uint64 stringAccount's maximum quota. It refers to the maximum quota the account can use in an EpochstakeAmount:bigint stringAmount of VITE coins staked for the account
Example
contract_getStakeList
Get the staking records of an account. The returned result is in ascending order by expiration height
Note: This method does not return legacy delegated staking records. To get an old delegated staking record, use
contract_getDelegatedStakeInfo
-
Parameters:
address:addressAddress of the accountpageIndex:intPage index, starting with 0pageSize:intPage size. Maximum 1000.
-
Returns:
StakeInfoListtotalStakeAmount:bigint stringTotal staking amounttotalStakeCount:intTotal staking recordsstakeList:Array<StakeInfo>stakeAddress:addressAddress of the staking accountstakeAmount:bigint stringStaking amountexpirationHeight:uint64 stringLock-up expiration heightbeneficiary:addressQuota beneficiaryexpirationTime:int64Estimated lock-up expiration time. In seconds.id:hashStaking Id. For legacy staking, this field is null.isDelegated:boolDeprecated. Returns false for all recordsdelegateAddress:addressDeprecated. Returns "vite_0000000000000000000000000000000000000000a4f3a0cb58" (zero address) for all recordsbid:uint8Deprecated. Returns 0 for all records
Note:
isDelegated,delegateAddressandbidare deprecated
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"totalStakeAmount": "1000000000000000000000",
"totalStakeCount": 1,
"stakeList": [
{
"stakeAmount": "1000000000000000000000",
"beneficiary": "vite_bd756f144d6aba40262c0d3f282b521779378f329198b591c3",
"expirationHeight": "1360",
"expirationTime": 1567490923,
"isDelegated": false,
"delegateAddress": "vite_0000000000000000000000000000000000000000a4f3a0cb58",
"stakeAddress": "vite_ab24ef68b84e642c0ddca06beec81c9acb1977bbd7da27a87a",
"bid": 0,
"id": "349ec3cec028b9768b05d75a384402dfbd790d406b1d2e54841f5bd3b8bdbf67"
}
]
}
}
contract_getRequiredStakeAmount
Calculate the minimum required staking amount of Vite coins in order to obtain the quota
-
Parameters:
uint64 string: Per-second raw quota supply. For example, in order to send a transaction that consumes 21,000 raw quota, a minimum of 280 (=21000/75) raw quota supply for every second in an epoch is required
-
Returns:
string bigint: Minimum staking amount
Example
contract_getDelegatedStakeInfo
Get a legacy delegated staking record.
Note: Delegated staking is deprecated
-
Parameters:
StakeQueryParamsstakeAddress:addressOriginal staking addressdelegateAddress:addressDelegate address. This often is the contract address that stakes on behalf of the original addressbeneficiary:addressQuota beneficiarybid:uint8Business id, used to mark different staking purposes.
-
Returns:
StakeInfostakeAddress:addressAddress of the staking accountstakeAmount:bigint stringStaking amountexpirationHeight:uint64 stringLock-up expiration heightbeneficiary:addressQuota beneficiaryexpirationTime:int64Estimated lock-up expiration time. In seconds.id:hashFor delegated staking, the staking id is null.isDelegated:booltruemeans it is delegated stakingdelegateAddress:addressDelegate addressbid:uint8Business id
Example
{
"jsonrpc": "2.0",
"id": 17,
"method": "contract_getDelegatedStakeInfo",
"params": [
{
"stakeAddress": "vite_56d8bd5c897ebd7e606c23b392d4a336222dd908437565a43c",
"delegateAddress": "vite_0000000000000000000000000000000000000006e82b8ba657",
"beneficiary": "vite_0000000000000000000000000000000000000006e82b8ba657",
"bid": 1
}
]
}
{
"jsonrpc": "2.0",
"id": 17,
"result": {
"stakeAmount": "502000000000000000000",
"beneficiary": "vite_0000000000000000000000000000000000000006e82b8ba657",
"expirationHeight": "9503969",
"expirationTime": 1570194042,
"isDelegated": true,
"delegateAddress": "vite_0000000000000000000000000000000000000006e82b8ba657",
"stakeAddress": "vite_56d8bd5c897ebd7e606c23b392d4a336222dd908437565a43c",
"bid": 1,
"id": null
}
}
contract_getSBPList
Get all SBPs registered by address. The returned result also includes the ones that have been cancelled in history
-
Parameters:
address:addressSBP registration address
-
Returns:
Array<SBPInfo>name:stringSBP nameblockProducingAddress:addressBlock creation addressrewardWithdrawAddress:addressReward withdrawal addressstakeAddress:addressRegistration addressstakeAmount:bigint stringStaking amount. In the mainnet, it is 1 million VITE.expirationHeight:uint64 stringLock-up expiration heightexpirationTime:int64Estimated lock-up expiration time. In seconds.revokeTime:int64The timestamp when the SBP was canceled. For valid SBP this field is 0.
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"name": "s1",
"blockProducingAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"rewardWithdrawAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"stakeAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"stakeAmount": "1000000000000000000000000",
"expirationHeight": "7776000",
"expirationTime": 1575266076,
"revokeTime": 0
}
]
}
contract_getSBPRewardPendingWithdrawal
Query for an SBP's unclaimed rewards
-
Parameters:
name:stringSBP name
-
Returns:
SBPRewardtotalReward:bigint stringTotal unclaimed rewardsblockProducingReward:bigint stringBlock creation rewardsvotingReward:bigint stringCandidate additional rewards (voting rewards)producedBlocks:uint64 stringNot implemented. Returns "0"targetBlocks:uint64 stringNot implemented. Returns "0"allRewardWithdrawed:booltruemeans the SBP has been cancelled and there is no unclaimed rewards left
Example
contract_getSBPRewardByTimestamp
Query for all SBP rewards according to the cycle of the timestamp. The method maps the given timestamp to the cycle and returns the SBP rewards generated in the cycle.
-
Parameters:
timestamp:int64Timestamp. In seconds
-
Returns:
SBPRewardInforewardMap:map<string, SBPReward>totalReward:bigint stringTotal rewardsblockProducingReward:bigint stringBlock creation rewardsvotingReward:bigint stringCandidate additional rewards (voting rewards)producedBlocks:uint64 stringActual blocks produced in the cycletargetBlocks:uint64 stringBlocks should be produced in the cycle
startTime:int64Cycle start time. In secondsendTime:int64Cycle end time. In secondscycle:uint64 stringCycle index
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"rewardMap": {
"s1": {
"blockProducingReward": "1499714611872146118517",
"votingReward": "746306845207209076970",
"totalReward": "2246021457079355195487",
"producedBlocks": "3153",
"targetBlocks": "3168",
"allRewardWithdrawed": false
},
"s2": {
"blockProducingReward": "0",
"votingReward": "0",
"totalReward": "0",
"producedBlocks": "0",
"targetBlocks": "3168",
"allRewardWithdrawed": false
}
},
"startTime": 1567396800,
"endTime": 1567483200,
"cycle": "104"
}
}
contract_getSBPRewardByCycle
Query for all SBP rewards by cycle
-
Parameters:
cycle:uint64 stringCycle index
-
Returns:
SBPRewardInforewardMap:map<string, SBPReward>totalReward:bigint stringTotal rewardsblockProducingReward:bigint stringBlock creation rewardsvotingReward:bigint stringCandidate additional rewards (voting rewards)producedBlocks:uint64 stringActual blocks produced in the cycletargetBlocks:uint64 stringBlocks should be produced in the cycle
startTime:int64Cycle start time. In secondsendTime:int64Cycle end time. In secondscycle:uint64 stringCycle index
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"rewardMap": {
"s1": {
"blockProducingReward": "1499714611872146118517",
"votingReward": "746306845207209076970",
"totalReward": "2246021457079355195487",
"producedBlocks": "3153",
"targetBlocks": "3168",
"allRewardWithdrawed": false
},
"s2": {
"blockProducingReward": "0",
"votingReward": "0",
"totalReward": "0",
"producedBlocks": "0",
"targetBlocks": "3168",
"allRewardWithdrawed": false
}
},
"startTime": 1567396800,
"endTime": 1567483200,
"cycle": "104"
}
}
contract_getSBP
Get SBP information by name
-
Parameters:
name:stringSBP name
-
Returns:
SBPInfoname:stringSBP nameblockProducingAddress:addressBlock creation addressrewardWithdrawAddress:addressReward withdrawal addressstakeAddress:addressRegistration addressstakeAmount:bigint stringStaking amount. In the mainnet, it is 1 million VITE.expirationHeight:uint64 stringLock-up expiration heightexpirationTime:int64Estimated lock-up expiration time. In seconds.revokeTime:int64The timestamp when the SBP was canceled. For valid SBP this field is 0.
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"name": "s1",
"blockProducingAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"rewardWithdrawAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"stakeAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"stakeAmount": "500000000000000000000000",
"expirationHeight": "7776000",
"expirationTime": 1575268146,
"revokeTime": 0
}
}
contract_getSBPVoteList
Get all SBP's current votes
-
Parameters: none
-
Returns:
Array<SBPVoteInfo>sbpName:stringSBP nameblockProducingAddress:addressBlock creation addressvotes:bigint stringNumber of votes
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"sbpName": "s1",
"blockProducingAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"votes": "100000000000000000000"
},
{
"sbpName": "s2",
"blockProducingAddress": "vite_0acbb1335822c8df4488f3eea6e9000eabb0f19d8802f57c87",
"votes": "50000000000000000000"
}
]
}
contract_getVotedSBP
Get the current voted SBP by account
-
Parameters:
address:addressAddress of the account
-
Returns:
VotedSBPInfoblockProducerName:stringSBP namestatus:uint8SBP status.2- the SBP is cancelled,1- SBP is validvotes:bigint stringNumber of votes. This also refers to the account's available VITE balance
Example
contract_getSBPVoteDetailsByCycle
Get the voting details of all SBPs by cycle
-
Parameters:
cycle:uint64 stringCycle index
-
Returns:
Array<VoteDetail>blockProducerName:stringSBP nametotalVotes:bigint stringTotal votesblockProducingAddress:addressBlock creation addresshistoryProducingAddresses:Array<address>Block creation addresses used by the SBP in historyaddressVoteMap:map<address, bigint string>Address-votes map
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"blockProducerName": "s1",
"totalVotes": "100000000000000000000",
"blockProducingAddress": "vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906",
"historyProducingAddresses": [
"vite_e41be57d38c796984952fad618a9bc91637329b5255cb18906"
],
"addressVoteMap": {
"vite_ab24ef68b84e642c0ddca06beec81c9acb1977bbd7da27a87a": "100000000000000000000"
}
},
{
"blockProducerName": "s2",
"totalVotes": "50000000000000000000",
"blockProducingAddress": "vite_0acbb1335822c8df4488f3eea6e9000eabb0f19d8802f57c87",
"historyProducingAddresses": [
"vite_0acbb1335822c8df4488f3eea6e9000eabb0f19d8802f57c87"
],
"addressVoteMap": {
"vite_56fd05b23ff26cd7b0a40957fb77bde60c9fd6ebc35f809c23": "50000000000000000000"
}
}
]
}
contract_getTokenInfoList
Get all tokens
-
Parameters:
pageIndex:intPage index, starting with 0pageSize:intPage size. Maximum 1000
-
Returns:
TokenInfoListtotalCount:intTotal number of tokenstokenInfoList:Array<TokenInfo>See TokenInfotokenName:stringToken nametokenSymbol:stringToken symboltotalSupply:big.IntTotal supplydecimals:uint8Decimal placesowner:AddressToken ownerisReIssuable:booltruemeans the token can be re-issuedmaxSupply:big.IntMaximum supplyisOwnerBurnOnly:booltruemeans only the token owner can burn the tokens. DeprecatedtokenId:TokenIdToken IDindex:uint16Token index
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"totalCount": 1,
"tokenInfoList": [
{
"tokenName": "Vite Token",
"tokenSymbol": "VITE",
"totalSupply": "1000000000000000000000000000",
"decimals": 18,
"owner": "vite_0000000000000000000000000000000000000004d28108e76b",
"tokenId": "tti_5649544520544f4b454e6e40",
"maxSupply": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"isReIssuable": true,
"index": 0,
"isOwnerBurnOnly": false
}
]
}
}
contract_getTokenInfoById
Get token by id
-
Parameters:
tokenId:tokenIdToken id
-
Returns:
TokenInfotokenName:stringToken nametokenSymbol:stringToken symboltotalSupply:big.IntTotal supplydecimals:uint8Decimal placesowner:AddressToken ownerisReIssuable:booltruemeans the token can be re-issuedmaxSupply:big.IntMaximum supplyisOwnerBurnOnly:booltruemeans only the token owner can burn the tokens. DeprecatedtokenId:TokenIdToken IDindex:uint16Token index
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tokenName": "VITE",
"tokenSymbol": "VITE",
"totalSupply": "999369292029736282857580488",
"decimals": 18,
"owner": "vite_0000000000000000000000000000000000000004d28108e76b",
"tokenId": "tti_5649544520544f4b454e6e40",
"maxSupply": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"isReIssuable": true,
"index": 0,
"isOwnerBurnOnly": false
}
}
contract_getTokenInfoListByOwner
Get tokens issued by owner
-
Parameters:
address:addressAddress of the owner account
-
Returns:
Array<TokenInfo>See TokenInfotokenName:stringToken nametokenSymbol:stringToken symboltotalSupply:big.IntTotal supplydecimals:uint8Decimal placesowner:AddressToken ownerisReIssuable:booltruemeans the token can be re-issuedmaxSupply:big.IntMaximum supplyisOwnerBurnOnly:booltruemeans only the token owner can burn the tokens. DeprecatedtokenId:TokenIdToken IDindex:uint16Token index
Example
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"tokenName": "VITE",
"tokenSymbol": "VITE",
"totalSupply": "999411106171319027184734227",
"decimals": 18,
"owner": "vite_0000000000000000000000000000000000000004d28108e76b",
"tokenId": "tti_5649544520544f4b454e6e40",
"maxSupply": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"isReIssuable": true,
"index": 0,
"isOwnerBurnOnly": false
}
]
}