const bytecode = await fetchBytecode(address, rpc);
const cbor = extractCBOR(bytecode);
const metadata = decodeCBOR(cbor);
- const { cidV0, cidV1 } = calculateCID(metadata);
- const json = await fetchJSONMetadata(cidV1, ipfs);
-
- result.textContent = JSON.stringify(json);
+ let output;
+ if (metadata.bzzr0 !== undefined) {
+ const hex = [...metadata.bzzr0].map(b => b.toString(16).padStart(2, '0')).join('');
+ output = 'Unable to fetch metadata because the smart contract uses a Swarm hash. Swarm hash below:\n';
+ output += `bzzr://${hex}`;
+ }
+ else if (metadata.bzzr1 !== undefined) {
+ const hex = [...metadata.bzzr0].map(b => b.toString(16).padStart(2, '0')).join('');
+ output = 'Unable to fetch metadata because the smart contract uses a Swarm hash. Swarm hash below:\n';
+ output += `bzz-raw://${hex}`;
+ }
+ else {
+ const { cidV0, cidV1 } = calculateCID(metadata);
+ output = JSON.stringify(await fetchJSONMetadata(cidV1, ipfs));
+ }
+
+ result.textContent = output;
})
</script>
</body>