Skip to main content

ERC721P

Git Source

Inherits: ERC721, IERC721P

Author: sina.eth

Simple example implementation of ERC721P.

A simple implementation of IERC721P.

State Variables​

idToBridgeData​

A mapping of tokenIds to their corresponding bridgeData.

mapping(uint256 => bytes) public idToBridgeData;

Functions​

constructor​

Immutably sets the Chronicle address.

constructor(Chronicle _chronicle) IERC721P(_chronicle);

Parameters

NameTypeDescription
_chronicleChronicleThe address that's used as the Chronicle to verify provenance against.

name​

Returns the token collection name.

function name() public pure virtual override returns (string memory);

symbol​

Returns the token collection symbol.

function symbol() public pure virtual override returns (string memory);

tokenURI​

Returns the Uniform Resource Identifier (URI) for token id. For this sample implementation, the tokenURI is taken to immutably be the bridgedTokenURI for the given tokenId and bridgeData.

function tokenURI(uint256 tokenId) public view virtual override returns (string memory);

Parameters

NameTypeDescription
tokenIduint256The token to query the URI for.

Returns

NameTypeDescription
<none>stringuri The URI for the given token.

getProvenanceHash​

Maps the given bridgeData to its provenance hash representation for verification.

Returns the hash used for the provenance of the token's data. In this sample implementation, we simply use the keccak256 hash of the bridgeData.

function getProvenanceHash(bytes calldata bridgeData) public view virtual override returns (bytes32);

Parameters

NameTypeDescription
bridgeDatabytes

Returns

NameTypeDescription
<none>bytes32hash The provenanceHash corresponding to the data.

getBridgedOwner​

Identifies the owner of the tokenId given its bridgeData.

Returns the owner of the token given the bridgeData. In this sample implementation, we simply decode the owner from the bridgeData.

function getBridgedOwner(uint256, bytes calldata bridgeData) public view virtual override returns (address owner);

Parameters

NameTypeDescription
<none>uint256
bridgeDatabytesThe bridgeData to use to identify the owner.

Returns

NameTypeDescription
owneraddressThe owner of the token.

bridgedTokenURI​

Returns the metadata URI for the tokenId given its bridgeData.

Returns the metadata URI for the token, as if it were minted to this contract. In this sample implementation, we simply decode the metadata URI from the bridgeData.

function bridgedTokenURI(uint256, bytes calldata bridgeData) public view virtual override returns (string memory uri);

Parameters

NameTypeDescription
<none>uint256
bridgeDatabytesThe bridgeData to use to construct the metadata URI.

Returns

NameTypeDescription
uristringtokenURI The metadata URI for the token.

bridge​

Bridge the provenance of and mint an NFT.

Bridges the provenance of and mints an NFT. In this sample implementation, we simply store the bridgeData as the NFT's data.

function bridge(
uint256 tokenId,
bytes calldata bridgeData,
bytes32[] calldata leftProof,
bytes32[] calldata rightProof,
bytes32 targetRoot
) public override;

Parameters

NameTypeDescription
tokenIduint256The index of the leaf to be verified in the tree.
bridgeDatabytesThe data of the NFT, to be converted to a leaf.
leftProofbytes32[]The left range of the proof.
rightProofbytes32[]The right range of the proof.
targetRootbytes32The root of the tree the proof is being verified against.