Docs

ContractMetadata

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

The ContractMetadata smart contract is an extension usable with any smart contract. It lets you define metadata for your smart contract. Additionally, ContractMetadata is necessary to enable royalties on NFT contracts on OpenSea.

View on GitHub

Usage

The ContractMetadata extension is an abstract contract, and expects you to implement the following functions by yourself:

NameTypeReturnsDescription
_canSetContractURIinternal view virtualboolRuns on every attempt to set the metadata of the contract. Returns whether contract metadata can be set in the given execution context.

This is an example smart contract demonstrating how to inherit from this extension and override the functions to add (optional) custom functionality.

// 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 view virtual override returns (bool){
        return msg.sender == deployer;
    }
}

Base Contracts Implementing This Extension

All of the base contracts implement this extension.

Full API reference