Meter Docs
Search…
json interface
The json interface is a json object describing the Application Binary Interface (ABI) for a smart contract. Using this json interface, web3.js is able to create JavaScript object representing the smart contract and its methods and events using the web3.eth.Contract object.

Specification

Functions:
    1.
    type: "function", "constructor" (can be omitted, defaulting to "function"; "fallback" also possible but not relevant in web3.js).
    2.
    name: the name of the function (only present for function types).
    3.
    constant: true if function is specified to not modify the blockchain state.
    4.
    payable: true if function accepts ether, defaults to false
    5.
    stateMutability: a string with one of the following values:
      1.
      pure (specified to not read blockchain state)
      2.
      view (same as constant above)
      3.
      nonpayable and payable (same as payable above)
    6.
    inputs: an array of objects, each of which contains:
      1.
      name: the name of the parameter
      2.
      type: the canonical type of the parameter
    7.
    outputs: an array of objects same as inputs, can be omitted if no outputs exist.
Events:
    1.
    type: always "event"
    2.
    name: the name of the event.
    3.
    inputs: an array of objects, each of which contains:
      1.
      name: the name of the parameter.
      2.
      type: the canonical type of the parameter.
      3.
      indexed: true if the field is part of the log's topics, false if it one of the log's data segment.
    4.
    anonymous: true if the event was declared as anonymous.
Example:
1
contract Test {
2
uint a;
3
address d = 0x12345678901234567890123456789012;
4
5
function Test(uint testInt) { a = testInt;}
6
7
event Event(uint indexed b, bytes32 c);
8
9
event Event2(uint indexed b, bytes32 c);
10
11
function foo(uint b, bytes32 c) returns(address) {
12
Event(b, c);
13
return d;
14
}
15
}
16
17
// would result in the JSON:
18
[{
19
"type":"constructor",
20
"payable":false,
21
"stateMutability":"nonpayable"
22
"inputs":[{"name":"testInt","type":"uint256"}],
23
},{
24
"type":"function",
25
"name":"foo",
26
"constant":false,
27
"payable":false,
28
"stateMutability":"nonpayable",
29
"inputs":[{"name":"b","type":"uint256"}, {"name":"c","type":"bytes32"}],
30
"outputs":[{"name":"","type":"address"}]
31
},{
32
"type":"event",
33
"name":"Event",
34
"inputs":[{"indexed":true,"name":"b","type":"uint256"}, {"indexed":false,"name":"c","type":"bytes32"}],
35
"anonymous":false
36
},{
37
"type":"event",
38
"name":"Event2",
39
"inputs":[{"indexed":true,"name":"b","type":"uint256"},{"indexed":false,"name":"c","type":"bytes32"}],
40
"anonymous":false
41
}]
Copied!
Last modified 1yr ago
Copy link