Contract API

Contracts

x86 is now in the development stage.

get_contract(contract_id)

Get a contract info from VM by ID.

Parameters

Option
Description
contract_id_type contract_id
ID of the contract to retrieve

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"get_contract",
7
[
8
"1.11.0"
9
]
10
]
11
}
Copied!

Returns

The contracts data from VM corresponding to the provided ID.
1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": [
5
0,
6
{
7
"code": "6080604052600436106100d557...",
8
"storage": [
9
[
10
"036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0",
11
[
12
"05",
13
"d3c21bcecceda1000000"
14
]
15
], ...
16
]
17
}
18
]
19
}
Copied!

get_contracts(contract_ids)

Get a list of contracts by ID.
Parameters
Option
Description
vector<contract_id_type> contract_ids
IDs of the contracts to retrieve

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"get_contracts",
7
[
8
"1.11.0",
9
"1.11.1", ...
10
]
11
]
12
}
Copied!

Returns

The contracts corresponding to the provided IDs.
1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": [
5
{
6
"id": "1.11.0",
7
"type": "evm",
8
"destroyed": false,
9
"statistics": "2.17.0",
10
"owner": "1.2.27",
11
"extensions": []
12
},
13
{
14
"id": "1.11.1",
15
"type": "evm",
16
"destroyed": false,
17
"statistics": "2.17.1",
18
"supported_asset_id": "1.3.0",
19
"owner": "1.2.38",
20
"extensions": []
21
}
22
]
23
}
Copied!

get_contract_logs(contract_logs_filter_options)

Returns an array of all logs matching a given filter object.

Parameters

Option
Description
function<void(const variant&)> cb
callback method which is called when contracts has logs
contract_logs_filter_options opts
The filter object

The filter options

Option
Description
set<contract_id_type> contracts
(optional) A list of contract ids from which logs should originate
vector<set<string>> topics
(optional) Topics are order-dependent. It’s possible to pass in empty array to match any topic, or a subarray of multiple topics of which one should be matching.
optional<uint32_t> from_block
(optional) Default: head_block_num - 1000.
optional<uint32_t> to_block
(optional) Default: head_block_num.
A note on specifying topic filters: Topics are order-dependent. A transaction with a log with topics [A, B] will be matched by the following topic filters:
    [] “anything”
    [[A]] “A in first position (and anything after)”
    [[], [B]] “anything in first position AND B in second position (and anything after)”
    [[A], [B]] “A in first position AND B in second position (and anything after)”
    [[A, B], [A, B]] “(A OR B) in first position AND (A OR B) in second position (and anything after)”

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"get_contract_logs",
7
[
8
CALLBACK_ID,
9
{
10
"contracts": [
11
"1.11.0"
12
],
13
"topics": [
14
[
15
"a1f905024bf9f0430b6d981173eb6df240bdf128fbadea8a869257b4015673e5"
16
],
17
[],
18
[
19
"0000000000000000000000000000000000000000000000000000000000000002",
20
"0000000000000000000000000000000000000000000000000000000000000004"
21
]
22
],
23
"from_block": "0",
24
"to_block": "100"
25
}
26
]
27
]
28
}
Copied!

Notice example

1
{
2
"method": "notice",
3
"params": [
4
CALLBACK_ID,
5
[
6
[
7
[
8
0,
9
{
10
"address": "0100000000000000000000000000000000000000",
11
"log": [
12
"bfed43b35c99a41ee9b8cb5a2afa74e45703b17dfd398a3b96260bdebca807cf"
13
],
14
"data": "",
15
"block_num": 14,
16
"trx_num": 0,
17
"op_num": 0
18
}
19
]
20
]
21
]
22
]
23
}
Copied!

subscribe_contracts(contracts_ids)

Subscription to change the contract uses set_subscribe_callback.

Parameters

Option
Description
vector<contract_id_type> contracts_ids
IDs of the contracts to subscribe

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"subscribe_contracts",
7
[
8
[
9
"1.11.0"
10
]
11
]
12
]
13
}
Copied!

Returns

1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": null
5
}
Copied!

Notice example

1
{
2
"method": "notice",
3
"params": [
4
CALLBACK_ID,
5
[
6
[
7
{
8
"address": "0100000000000000000000000000000000000003",
9
"log": [
10
"a1f905024bf9f0430b6d981173eb6df240bdf128fbadea8a869257b4015673e5"
11
],
12
"data": "0000000000000000000000000000000000000000000000000000000000000097",
13
"block_num": 14,
14
"trx_num": 0,
15
"op_num": 0
16
}
17
]
18
]
19
]
20
}
Copied!

subscribe_contract_logs(cb_id, cb, contract_id)

Subscribe to specified contract logs.

Parameters

Option
Description
uint64_t cb_id
Callback id which is referenced in notice when contracts has new logs
function<void(variant)> cb
callback method which is called when contracts has new logs
map<contract_id_type, std::set<string>> subs
Pairs of contract ids and topic filters

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"subscribe_contract_logs",
7
[
8
CALLBACK_ID,
9
{
10
1.11.0 : []
11
}
12
]
13
]
14
}
Copied!

Returns

The contracts logs by contract ID.
1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": null
5
}
Copied!

Notice example

1
{
2
"method": "notice",
3
"params": [
4
CALLBACK_ID,
5
[
6
[
7
[
8
0,
9
{
10
"address": "0100000000000000000000000000000000000000",
11
"log": [
12
"bfed43b35c99a41ee9b8cb5a2afa74e45703b17dfd398a3b96260bdebca807cf"
13
],
14
"data": "",
15
"block_num": 14,
16
"trx_num": 0,
17
"op_num": 0
18
}
19
]
20
]
21
]
22
]
23
}
Copied!

unsubscribe_contract_logs(cb_id)

Unsubscribe from contract log subscription

Parameters

Option
Description
uint64_t cb_id
Callback id of subscription

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"unsubscribe_contract_logs",
7
[
8
CALLBACK_ID
9
]
10
]
11
}
Copied!

Returns

1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": null
5
}
Copied!

get_contract_result(id)

Get contract result from VM for specified result_id

Parameters

Option
Description
contract_result_id_type id
ID of result to retrieve

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"get_contract_result",
7
[
8
"1.12.0"
9
]
10
]
11
}
Copied!

Returns

Result of execution.
1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": [
5
0,
6
{
7
"exec_res": {
8
"excepted": "None",
9
"new_address": "0100000000000000000000000000000000000000",
10
"output": "608060405260...",
11
"code_deposit": "Success",
12
"gas_for_deposit": 720877,
13
"deposit_size": 2601
14
},
15
"tr_receipt": {
16
"status_code": 1,
17
"gas_used": 885323,
18
"bloom": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
19
"log": []
20
}
21
}
22
]
23
}
Copied!

call_contract_no_changing_state(contract_id, caller, value, code)

Call the provided contract, but don't change the state.

Parameters

Option
Description
contract_id_type contract_id
ID of the contract
object_id_type caller
id of the caller(contract or account)
asset value
the type of the asset transfered to the contract
string code
the hash of the method to call(or name for x86-x64 contracts)

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"call_contract_no_changing_state",
7
[
8
"1.11.0",
9
"1.2.26",
10
{"amount": 100,"asset_id": "1.3.0"},
11
"6d4ce63c"
12
]
13
]
14
}
Copied!

Returns

Result of execution.
1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": "0000000000000000000000000000000000000000000000000000000000000093"
5
}
Copied!

Contract Feepool

get_contract_pool_balance(id)

Get a contract's pool balance in default asset.

Parameters

Option
Description
contract_id_type id
ID of the contract to get balances for

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"get_contract_pool_balance",
7
[
8
"1.11.0"
9
]
10
]
11
}
Copied!

Returns

Balances of the contract.
1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": {
5
"amount": 1,
6
"asset_id": "1.3.0"
7
}
8
}
Copied!

get_contract_pool_whitelist(id)

Get a contract's whitelist and blacklist.

Parameters

Option
Description
contract_id_type id
ID of the contract

Example

1
{
2
"id": 4,
3
"method": "call",
4
"params": [
5
DATABASE_API_ID,
6
"get_contract_pool_whitelist",
7
[
8
"1.11.0"
9
]
10
]
11
}
Copied!

Returns

Struct contract_pool_whitelist which consist of whitelist blacklist.
1
{
2
"id": 4,
3
"jsonrpc": "2.0",
4
"result": {
5
"whitelist": [
6
"1.2.1"
7
],
8
"blacklist": [
9
"1.2.2"
10
]
11
}
12
}
Copied!
Last modified 1yr ago