Skip to main content

Contract Metadata

The ContractMetadata smart contract is an extension usable with any base smart contract. It lets you associate arbitrary metadata with your smart contract.

Unlocked Features

Once deployed, you can use the features made available by these contracts on the SDK and dashboard:

Implementing the Contract

Import the contract extension and make your contract inherit it.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@thirdweb-dev/contracts/extension/ContractMetadata.sol";

contract MyContract is ContractMetadata {

/**
* We store the contract deployer's address only for the purposes of the example
* in the code comment below.
*
* Doing this is not necessary to use the `ContractMetadata` extension.
*/
address public deployer;

constructor() {
deployer = msg.sender;
}

/**
* This function returns who is authorized to set the metadata for your metadata.
*
* As an EXAMPLE, we'll only allow the contract deployer to set the contract's metadata.
*
* You MUST complete the body of this function to use the `ContractMetadata` extension.
*/
function _canSetContractURI() internal virtual override returns (bool){
return msg.sender == deployer;
}
}