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
:address
Account addressheight
:uint64 string
Height of the account blockpreviousHash
:hash
Hash of the previous account block
-
Returns:
address
New contract address
Example
contract_getContractInfo
Get contract information by address
-
Parameters:
address
:address
Address of the contract
-
Returns:
ContractInfo
code
:base64
Binary code of the contractgid
:gid
Consensus group id. Default is00000000000000000002
responseLatency
:uint8
Response latencyrandomDegree
:uint8
Random degreequotaMultiplier
:uint8
Quota 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:
CallOffChainMethodParam
address
:address
Contract addresscode
:base64
Binary code of the offchain methoddata
:base64
Encoded arguments
-
Returns:
base64
Encoded 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:
QueryParam
address
:address
Contract addressdata
:base64
Encoded arguments
-
Returns:
base64
Encoded calling result in base64 string
Example
contract_getContractStorage
Query for a contract's states by search key
-
Parameters:
addr
:address
Address of the contractprefix
:hex
Search 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
:address
Address of the account
-
Returns:
QuotaInfo
currentQuota
:uint64 string
Account's available quotamaxQuota
:uint64 string
Account's maximum quota. It refers to the maximum quota the account can use in an EpochstakeAmount
:bigint string
Amount 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
:address
Address of the accountpageIndex
:int
Page index, starting with 0pageSize
:int
Page size. Maximum 1000.
-
Returns:
StakeInfoList
totalStakeAmount
:bigint string
Total staking amounttotalStakeCount
:int
Total staking recordsstakeList
:Array<StakeInfo>
stakeAddress
:address
Address of the staking accountstakeAmount
:bigint string
Staking amountexpirationHeight
:uint64 string
Lock-up expiration heightbeneficiary
:address
Quota beneficiaryexpirationTime
:int64
Estimated lock-up expiration time. In seconds.id
:hash
Staking Id. For legacy staking, this field is null.isDelegated
:bool
Deprecated. Returns false for all recordsdelegateAddress
:address
Deprecated. Returns "vite_0000000000000000000000000000000000000000a4f3a0cb58" (zero address) for all recordsbid
:uint8
Deprecated. Returns 0 for all records
Note:
isDelegated
,delegateAddress
andbid
are 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:
StakeQueryParams
stakeAddress
:address
Original staking addressdelegateAddress
:address
Delegate address. This often is the contract address that stakes on behalf of the original addressbeneficiary
:address
Quota beneficiarybid
:uint8
Business id, used to mark different staking purposes.
-
Returns:
StakeInfo
stakeAddress
:address
Address of the staking accountstakeAmount
:bigint string
Staking amountexpirationHeight
:uint64 string
Lock-up expiration heightbeneficiary
:address
Quota beneficiaryexpirationTime
:int64
Estimated lock-up expiration time. In seconds.id
:hash
For delegated staking, the staking id is null.isDelegated
:bool
true
means it is delegated stakingdelegateAddress
:address
Delegate addressbid
:uint8
Business 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
:address
SBP registration address
-
Returns:
Array<SBPInfo>
name
:string
SBP nameblockProducingAddress
:address
Block creation addressrewardWithdrawAddress
:address
Reward withdrawal addressstakeAddress
:address
Registration addressstakeAmount
:bigint string
Staking amount. In the mainnet, it is 1 million VITE.expirationHeight
:uint64 string
Lock-up expiration heightexpirationTime
:int64
Estimated lock-up expiration time. In seconds.revokeTime
:int64
The 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
:string
SBP name
-
Returns:
SBPReward
totalReward
:bigint string
Total unclaimed rewardsblockProducingReward
:bigint string
Block creation rewardsvotingReward
:bigint string
Candidate additional rewards (voting rewards)producedBlocks
:uint64 string
Not implemented. Returns "0"targetBlocks
:uint64 string
Not implemented. Returns "0"allRewardWithdrawed
:bool
true
means 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
:int64
Timestamp. In seconds
-
Returns:
SBPRewardInfo
rewardMap
:map<string, SBPReward>
totalReward
:bigint string
Total rewardsblockProducingReward
:bigint string
Block creation rewardsvotingReward
:bigint string
Candidate additional rewards (voting rewards)producedBlocks
:uint64 string
Actual blocks produced in the cycletargetBlocks
:uint64 string
Blocks should be produced in the cycle
startTime
:int64
Cycle start time. In secondsendTime
:int64
Cycle end time. In secondscycle
:uint64 string
Cycle 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 string
Cycle index
-
Returns:
SBPRewardInfo
rewardMap
:map<string, SBPReward>
totalReward
:bigint string
Total rewardsblockProducingReward
:bigint string
Block creation rewardsvotingReward
:bigint string
Candidate additional rewards (voting rewards)producedBlocks
:uint64 string
Actual blocks produced in the cycletargetBlocks
:uint64 string
Blocks should be produced in the cycle
startTime
:int64
Cycle start time. In secondsendTime
:int64
Cycle end time. In secondscycle
:uint64 string
Cycle 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
:string
SBP name
-
Returns:
SBPInfo
name
:string
SBP nameblockProducingAddress
:address
Block creation addressrewardWithdrawAddress
:address
Reward withdrawal addressstakeAddress
:address
Registration addressstakeAmount
:bigint string
Staking amount. In the mainnet, it is 1 million VITE.expirationHeight
:uint64 string
Lock-up expiration heightexpirationTime
:int64
Estimated lock-up expiration time. In seconds.revokeTime
:int64
The 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
:string
SBP nameblockProducingAddress
:address
Block creation addressvotes
:bigint string
Number 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
:address
Address of the account
-
Returns:
VotedSBPInfo
blockProducerName
:string
SBP namestatus
:uint8
SBP status.2
- the SBP is cancelled,1
- SBP is validvotes
:bigint string
Number 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 string
Cycle index
-
Returns:
Array<VoteDetail>
blockProducerName
:string
SBP nametotalVotes
:bigint string
Total votesblockProducingAddress
:address
Block 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
:int
Page index, starting with 0pageSize
:int
Page size. Maximum 1000
-
Returns:
TokenInfoList
totalCount
:int
Total number of tokenstokenInfoList
:Array<TokenInfo>
See TokenInfotokenName
:string
Token nametokenSymbol
:string
Token symboltotalSupply
:big.Int
Total supplydecimals
:uint8
Decimal placesowner
:Address
Token ownerisReIssuable
:bool
true
means the token can be re-issuedmaxSupply
:big.Int
Maximum supplyisOwnerBurnOnly
:bool
true
means only the token owner can burn the tokens. DeprecatedtokenId
:TokenId
Token IDindex
:uint16
Token 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
:tokenId
Token id
-
Returns:
TokenInfo
tokenName
:string
Token nametokenSymbol
:string
Token symboltotalSupply
:big.Int
Total supplydecimals
:uint8
Decimal placesowner
:Address
Token ownerisReIssuable
:bool
true
means the token can be re-issuedmaxSupply
:big.Int
Maximum supplyisOwnerBurnOnly
:bool
true
means only the token owner can burn the tokens. DeprecatedtokenId
:TokenId
Token IDindex
:uint16
Token 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
:address
Address of the owner account
-
Returns:
Array<TokenInfo>
See TokenInfotokenName
:string
Token nametokenSymbol
:string
Token symboltotalSupply
:big.Int
Total supplydecimals
:uint8
Decimal placesowner
:Address
Token ownerisReIssuable
:bool
true
means the token can be re-issuedmaxSupply
:big.Int
Maximum supplyisOwnerBurnOnly
:bool
true
means only the token owner can burn the tokens. DeprecatedtokenId
:TokenId
Token IDindex
:uint16
Token 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
}
]
}