Swarm URL in Truffle metadata

I have some questions that I can’t seem to find a clear answer on other resources.
After truffle compile, artifact json file comes out and there is metadata in the file. It is json, so I formatted it:

There is Swarm url in sources. What does it mean? Does it mean truffle uploaded the contract source to Swarm? If so, how can I get the source? I can’t get it from https://swarm-gateways.net
Besides, some other Swarm url is not bzzr:// but bzz:/
Let me know if anything is missing.

1 Like

Hi @swkim109,

It is a content addressable hash of the metadata. We need to publish the metadata file to IPFS, Swarm etc ourselves, the compiler doesn’t do this for us.

For details see: https://solidity.readthedocs.io/en/v0.6.11/metadata.html
I have copied some relevant sections below:

The compiler appends by default the IPFS hash of the metadata file to the end of the bytecode (for details, see below) of each contract

You have to publish the metadata file to IPFS, Swarm, or another service so that others can access it.

In order to verify the compilation, sources can be retrieved from IPFS/Swarm via the link in the metadata file.

Also see:

1 Like

Thanks for the answer!
But one thing I didn’t understand is the difference hash of bzzr and bzz. When I uploaded the contract source(.sol) via https://swarm-gateways.net, Swarm hash is not the same as Truffle bzzr:// hash. So I think that verifying the compilation of Truffle is not possible.

1 Like

Hi @swkim109,

I assume bzzr might be bzz-raw?
https://swarm-guide.readthedocs.io/en/latest/features/bzz.html#bzz-url-schemes

I think documentation is still thin on the ground for this. I was reading throug the sourcify FAQ:

Hi @swkim109,

Some more background information

from: https://blog.openzeppelin.com/deconstructing-a-solidity-contract-part-vi-the-swarm-hash-70f069e22aef/

Solidity uses a type of encoding called CBOR encoding, with which not only the hash is stored, but the specific decentralized storage system and version used is stored. In this case, it’s using Swarm’s version zero bzz:// URL scheme and that’s why the structure contains the chars “b”, “z”, “z”, “r”, “0”. Alternatively, it could use something like “i”, “p”, “f”, “s”, “r”, “0”, indicating that the structure encodes an IPFS URL scheme. This makes it agnostic in terms of which storage system is used. It could be changed in the future, or we could even get to choose which storage system we want the bytecode to reference upon compilation.

I have no idea but nothing wrong in remix.
metadata is:

And I can get the contract source from the following link:
Swarm-gateway

1 Like

Hi @swkim109,

It looks like Remix supports publishing the metadata file then. I don’t know if that is an option with Truffle yet (or if there is a plugin).

I saw that you had asked in Spectrum so let me know if you hear anything.

1 Like