@@ -10,16 +10,18 @@ this file to query the compiler version, the sources used, the ABI and NatSpec
1010documentation to more safely interact with the contract and verify its source
1111code.
1212
13- The compiler appends a Swarm hash of the metadata file to the end of the
14- bytecode (for details, see below) of each contract, so that you can retrieve
15- the file in an authenticated way without having to resort to a centralized
16- data provider.
17-
18- You have to publish the metadata file to Swarm (or another service) so that
19- others can access it. You create the file by using the ``solc --metadata ``
13+ The compiler appends by default the IPFS hash of the metadata file to the end
14+ of the bytecode (for details, see below) of each contract, so that you can
15+ retrieve the file in an authenticated way without having to resort to a
16+ centralized data provider. The other available options are the Swarm hash and
17+ not appending the metadata hash to the bytecode. These can be configured via
18+ the :ref: `Standard JSON Interface<compiler-api> `.
19+
20+ You have to publish the metadata file to IPFS, Swarm, or another service so
21+ that others can access it. You create the file by using the ``solc --metadata ``
2022command that generates a file called ``ContractName_meta.json ``. It contains
21- Swarm references to the source code, so you have to upload all source files and
22- the metadata file.
23+ IPFS and Swarm references to the source code, so you have to upload all source
24+ files and the metadata file.
2325
2426The metadata file has the following format. The example below is presented in a
2527human-readable way. Properly formatted metadata should use quotes correctly,
@@ -86,7 +88,9 @@ explanatory purposes.
8688 },
8789 metadata: {
8890 // Reflects the setting used in the input json, defaults to false
89- useLiteralContent: true
91+ useLiteralContent: true,
92+ // Reflects the setting used in the input json, defaults to "ipfs"
93+ bytecodeHash: "ipfs"
9094 }
9195 // Required for Solidity: File and name of the contract or library this
9296 // metadata is created for.
@@ -111,8 +115,8 @@ explanatory purposes.
111115 }
112116
113117 .. warning ::
114- Since the bytecode of the resulting contract contains the metadata hash, any
115- change to the metadata results in a change of the bytecode. This includes
118+ Since the bytecode of the resulting contract contains the metadata hash by default , any
119+ change to the metadata might result in a change of the bytecode. This includes
116120 changes to a filename or path, and since the metadata includes a hash of all the
117121 sources used, a single whitespace change results in different metadata, and
118122 different bytecode.
@@ -124,46 +128,46 @@ Encoding of the Metadata Hash in the Bytecode
124128=============================================
125129
126130Because we might support other ways to retrieve the metadata file in the future,
127- the mapping ``{"bzzr1 ": <Swarm hash>, "solc": <compiler version>} `` is stored
131+ the mapping ``{"ipfs ": <IPFS hash>, "solc": <compiler version>} `` is stored
128132`CBOR <https://tools.ietf.org/html/rfc7049 >`_-encoded. Since the mapping might
129133contain more keys (see below) and the beginning of that
130134encoding is not easy to find, its length is added in a two-byte big-endian
131135encoding. The current version of the Solidity compiler usually adds the following
132136to the end of the deployed bytecode::
133137
134138 0xa2
135- 0x65 'b ' 'z ' 'z ' 'r' '1' 0x58 0x20 <32 bytes swarm hash>
139+ 0x64 'i ' 'p ' 'f ' 's' 0x58 0x22 <34 bytes IPFS hash>
136140 0x64 's' 'o' 'l' 'c' 0x43 <3 byte version encoding>
137141 0x00 0x32
138142
139143So in order to retrieve the data, the end of the deployed bytecode can be checked
140- to match that pattern and use the Swarm hash to retrieve the file.
144+ to match that pattern and use the IPFS hash to retrieve the file.
141145
142146Whereas release builds of solc use a 3 byte encoding of the version as shown
143147above (one byte each for major, minor and patch version number), prerelease builds
144148will instead use a complete version string including commit hash and build date.
145149
146150.. note ::
147151 The CBOR mapping can also contain other keys, so it is better to fully
148- decode the data instead of relying on it starting with ``0xa265 ``.
152+ decode the data instead of relying on it starting with ``0xa264 ``.
149153 For example, if any experimental features that affect code generation
150154 are used, the mapping will also contain ``"experimental": true ``.
151155
152156.. note ::
153- The compiler currently uses the "swarm version 1" hash of the metadata,
154- but this might change in the future, so do not rely on this sequence
155- to start with ``0xa2 0x65 'b ' 'z ' 'z ' 'r' '1' ``. We might also
156- add additional data to this CBOR structure, so the
157- best option is to use a proper CBOR parser.
157+ The compiler currently uses the IPFS hash of the metadata by default, but
158+ it may also use the bzzr1 hash or some other hash in the future, so do
159+ not rely on this sequence to start with ``0xa2 0x64 'i ' 'p ' 'f ' 's' ``. We
160+ might also add additional data to this CBOR structure, so the best option
161+ is to use a proper CBOR parser.
158162
159163
160164Usage for Automatic Interface Generation and NatSpec
161165====================================================
162166
163167The metadata is used in the following way: A component that wants to interact
164- with a contract (e.g. Mist or any wallet) retrieves the code of the contract, from that
165- the Swarm hash of a file which is then retrieved.
166- That file is JSON-decoded into a structure like above.
168+ with a contract (e.g. Mist or any wallet) retrieves the code of the contract,
169+ from that the IPFS/ Swarm hash of a file which is then retrieved. That file
170+ is JSON-decoded into a structure like above.
167171
168172The component can then use the ABI to automatically generate a rudimentary
169173user interface for the contract.
@@ -177,7 +181,7 @@ For additional information, read :doc:`Ethereum Natural Language Specification (
177181Usage for Source Code Verification
178182==================================
179183
180- In order to verify the compilation, sources can be retrieved from Swarm
184+ In order to verify the compilation, sources can be retrieved from IPFS/ Swarm
181185via the link in the metadata file.
182186The compiler of the correct version (which is checked to be part of the "official" compilers)
183187is invoked on that input with the specified settings. The resulting
0 commit comments