So, I've created two folders on IPFS.
Images CID: QmRcEhMDmSMQuXFZXsg73w76eKqVEFZGy8cSvn9PfUw7bH
Folder CID: QmPsG54TQRaeuqRexDXxd77E916zMugjsqmifH2QTvAmxr
Folder looks like below:
And 0x000...13.json:
{
"description": "In Memory of Steve Irwin",
"image": "ipfs://QmRcEhMDmSMQuXFZXsg73w76eKqVEFZGy8cSvn9PfUw7bH/13.jpg",
"name": "13"
}
and images:
As you can see I padded the metadata file names to hexadecimal. (e.g: 1.json is 000...01.json, 63 zeros before the last 1). For some reason, OpenSea can load the images with 1 digit but not the 2 digits (it loads 1,2,3,...9.jsons but not the 10,11,12 and 13.jsons). What am I doing wrong here?
The OpenSea link for the collection: click here
frangio
February 18, 2022, 11:23pm
2
The issue is not numbers with two digits, but numbers where the base-10 representation is different from base-16/hexadecimal!
EIP-1155 specifies that {id}
is replaced with the hex-encoded id. Previous discussion here:
The EIP says:
The string format of the substituted hexadecimal ID MUST be lowercase alphanumeric: [0-9a-f] with no 0x prefix.
The string format of the substituted hexadecimal ID MUST be leading zero padded to 64 hex characters length if necessary.
So given a URI like ipfs://uri/{id}.json for token with id 250, a compliant client would have to use the last one you shared:
ipfs://uri/00000000000000000000000000000000000000000000000000000000000000fa.json
Here's an implementation in JavaScript:
const makeUri = (uri, id) => uri.replace('{id}', id.toString(16).padStart(64, '0'));
> makeUri('ipfs://uri/{id}.json', 250)
'ipfs://uri/00000000000000000000000000000000000000000000000000000000000000fa.json'
1 Like