Skip to content

Commit 0bec0e8

Browse files
author
Leo
authored
Merge pull request #13397 from kuzdogan/patch-1
Update Metadata docs
2 parents c4d9cdf + 5849fc3 commit 0bec0e8

File tree

1 file changed

+73
-18
lines changed

1 file changed

+73
-18
lines changed

docs/metadata.rst

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ explanatory purposes.
4646
// to the language.
4747
"compiler": {
4848
// Required for Solidity: Version of the compiler
49-
"version": "0.4.6+commit.2dabbdf0.Emscripten.clang",
49+
"version": "0.8.2+commit.661d1103",
5050
// Optional: Hash of the compiler binary which produced this output
5151
"keccak256": "0x123..."
5252
},
53-
// Required: Compilation source files/source units, keys are file names
53+
// Required: Compilation source files/source units, keys are file paths
5454
"sources":
5555
{
56-
"myFile.sol": {
56+
"myDirectory/myFile.sol": {
5757
// Required: keccak256 hash of the source file
5858
"keccak256": "0x123...",
5959
// Required (unless "content" is used, see below): Sorted URL(s)
60-
// to the source file, protocol is more or less arbitrary, but a
61-
// Swarm URL is recommended
62-
"urls": [ "bzzr://56ab..." ],
60+
// to the source file, protocol is more or less arbitrary, but an
61+
// IPFS URL is recommended
62+
"urls": [ "bzz-raw://7d7a...", "dweb:/ipfs/QmN..." ],
6363
// Optional: SPDX license identifier as given in the source file
6464
"license": "MIT"
6565
},
@@ -73,7 +73,7 @@ explanatory purposes.
7373
// Required: Compiler settings
7474
"settings":
7575
{
76-
// Required for Solidity: Sorted list of remappings
76+
// Required for Solidity: Sorted list of import remappings
7777
"remappings": [ ":g=/dir" ],
7878
// Optional: Optimizer settings. The fields "enabled" and "runs" are deprecated
7979
// and are only given for backwards-compatibility.
@@ -100,15 +100,15 @@ explanatory purposes.
100100
}
101101
},
102102
"metadata": {
103-
// Reflects the setting used in the input json, defaults to false
103+
// Reflects the setting used in the input json, defaults to "false"
104104
"useLiteralContent": true,
105105
// Reflects the setting used in the input json, defaults to "ipfs"
106106
"bytecodeHash": "ipfs"
107107
},
108-
// Required for Solidity: File and name of the contract or library this
108+
// Required for Solidity: File path and the name of the contract or library this
109109
// metadata is created for.
110110
"compilationTarget": {
111-
"myFile.sol": "MyContract"
111+
"myDirectory/myFile.sol": "MyContract"
112112
},
113113
// Required for Solidity: Addresses for libraries used
114114
"libraries": {
@@ -118,12 +118,66 @@ explanatory purposes.
118118
// Required: Generated information about the contract.
119119
"output":
120120
{
121-
// Required: ABI definition of the contract
121+
// Required: ABI definition of the contract. See "Contract ABI Specification"
122122
"abi": [/* ... */],
123+
// Required: NatSpec developer documentation of the contract.
124+
"devdoc": {
125+
"version": 1 // NatSpec version
126+
"kind": "dev",
127+
// Contents of the @author NatSpec field of the contract
128+
"author": "John Doe",
129+
// Contents of the @title NatSpec field of the contract
130+
"title": "MyERC20: an example ERC20"
131+
// Contents of the @dev NatSpec field of the contract
132+
"details": "Interface of the ERC20 standard as defined in the EIP. See https://eips.ethereum.org/EIPS/eip-20 for details",
133+
"methods": {
134+
"transfer(address,uint256)": {
135+
// Contents of the @dev NatSpec field of the method
136+
"details": "Returns a boolean value indicating whether the operation succeeded. Must be called by the token holder address",
137+
// Contents of the @param NatSpec fields of the method
138+
"params": {
139+
"_value": "The amount tokens to be transferred",
140+
"_to": "The receiver address"
141+
}
142+
// Contents of the @return NatSpec field.
143+
"returns": {
144+
// Return var name (here "success") if exists. "_0" as key if return var is unnamed
145+
"success": "a boolean value indicating whether the operation succeeded"
146+
}
147+
}
148+
},
149+
"stateVariables": {
150+
"owner": {
151+
// Contents of the @dev NatSpec field of the state variable
152+
"details": "Must be set during contract creation. Can then only be changed by the owner"
153+
}
154+
}
155+
"events": {
156+
"Transfer(address,address,uint256)": {
157+
"details": "Emitted when `value` tokens are moved from one account (`from`) toanother (`to`)."
158+
"params": {
159+
"from": "The sender address"
160+
"to": "The receiver address"
161+
"value": "The token amount"
162+
}
163+
}
164+
}
165+
},
123166
// Required: NatSpec user documentation of the contract
124-
"userdoc": [/* ... */],
125-
// Required: NatSpec developer documentation of the contract
126-
"devdoc": [/* ... */]
167+
"userdoc": {
168+
"version": 1 // NatSpec version
169+
"kind": "user",
170+
"methods": {
171+
"transfer(address,uint256)": {
172+
"notice": "Transfers `_value` tokens to address `_to`"
173+
}
174+
},
175+
"events": {
176+
"Transfer(address,address,uint256)": {
177+
"notice": "`_value` tokens have been moved from `from` to `to`"
178+
}
179+
}
180+
}
127181
}
128182
}
129183
@@ -160,7 +214,7 @@ to the end of the deployed bytecode
160214
0x00 0x33
161215
162216
So in order to retrieve the data, the end of the deployed bytecode can be checked
163-
to match that pattern and use the IPFS hash to retrieve the file.
217+
to match that pattern and the IPFS hash can be used to retrieve the file (if pinned/published).
164218

165219
Whereas release builds of solc use a 3 byte encoding of the version as shown
166220
above (one byte each for major, minor and patch version number), prerelease builds
@@ -184,14 +238,15 @@ Usage for Automatic Interface Generation and NatSpec
184238
====================================================
185239

186240
The metadata is used in the following way: A component that wants to interact
187-
with a contract (e.g. Mist or any wallet) retrieves the code of the contract,
188-
from that the IPFS/Swarm hash of a file which is then retrieved. That file
241+
with a contract (e.g. a wallet) retrieves the code of the contract.
242+
It decodes the CBOR encoded section containing the IPFS/Swarm hash of the
243+
metadata file. With that hash, the metadata file is retrieved. That file
189244
is JSON-decoded into a structure like above.
190245

191246
The component can then use the ABI to automatically generate a rudimentary
192247
user interface for the contract.
193248

194-
Furthermore, the wallet can use the NatSpec user documentation to display a confirmation message to the user
249+
Furthermore, the wallet can use the NatSpec user documentation to display a human-readable confirmation message to the user
195250
whenever they interact with the contract, together with requesting
196251
authorization for the transaction signature.
197252

0 commit comments

Comments
 (0)