Skip to content
Verified contractExactMIT

NFTBookArt

Address0xfad35be3d5746919218f63abc91feace0e2f3ff8
Balance

0 ETH

 

Transactions

5

 

Compiler

solc 0.8.19

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.19+commit.7dd6d404
Language
solidity
Optimization
Yes, 1,000 runs
EVM version
paris
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
19,899,009
Creation transaction
0x61cc25af2b…dc3dba3c57

contracts/NBART/NFTBookArt.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

// Local References
import './NFTBookArtBase.sol';

/**
 * _________ .__           .__                      __  .__
 * \_   ___ \|  |__ _____  |__| ____   ____ _____ _/  |_|__|__  __ ____
 * /    \  \/|  |  \\__  \ |  |/    \ /    \\__  \\   __\  \  \/ // __ \
 * \     \___|   Y  \/ __ \|  |   |  \   |  \/ __ \|  | |  |\   /\  ___/
 *  \______  /___|  (____  /__|___|  /___|  (____  /__| |__| \_/  \___  >
 *         \/     \/     \/        \/     \/     \/                   \/
 *                  ____          _   _ ______ _______
 *                 / __ \        | \ | |  ____|__   __|
 *                | |  | |_ __   |  \| | |__     | |___
 *                | |  | | '_ \  | . ` |  __|    | / __|
 *                | |__| | | | | | |\  | |       | \__ \
 *                 \____/|_| |_| |_| \_|_|       |_|___/
 *
 * @title NFTBookArt
 * @dev Thanks to Patrick Gillespie (@patorjk) for Text to ASCII Art Generator (TAAG).
 */
contract NFTBookArt is NFTBookArtBase {
    uint256 private constant maxNumberOfArtPieces = 4;

    constructor() AbstractArtManager(maxNumberOfArtPieces) {
        // Implementation version: v1.0.0
    }
}

@nftculture/nftc-contracts-private/contracts/access/v2/OwnableDeferral.sol

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

/**
 * @title OwnableDeferral
 * @author @NiftyMike | @NFTCulture
 * @dev Implements checks for contract admin operations. Will be Backed by
 * OZ Ownable.
 *
 * This contract is helpful when a contract tree gets complicated,
 * and multiple contracts need to leverage Ownable.
 *
 * Sample Implementation:
 *
 * modifier isOwner() override(...) {
 *     _isOwner();
 *     _;
 * }
 *
 * function _isOwner() internal view override(...) {
 *     _checkOwner();
 * }
 */
abstract contract OwnableDeferral {
    modifier isOwner() virtual;

    function _isOwner() internal view virtual;
}

@nftculture/nftc-contracts-private/contracts/access/v2/OwnableDeferralResolution.sol

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

// OZ Libraries
import '@openzeppelin/contracts/access/Ownable.sol';

// Local References
import './OwnableDeferral.sol';

// Error Codes
error CallerIsNotOwner();

/**
 * @title OwnableDeferralResolution
 * @author @NiftyMike | @NFTCulture
 * @dev Implements checks for contract admin (Owner) operations. Backed by OZ Ownable.
 *
 * Ownership is assigned to contract deployer wallet by default.
 *
 * NOTE: IMPORTANT - This resolution will work great in a simple inheritance situation,
 * however, if multiple inheritance is involved, it might not adequately satisfy
 * override (...) conditions. In those scenarios, this code should be used as a
 * starting point and then adjusted appropriately.
 */
contract OwnableDeferralResolution is Ownable, OwnableDeferral {
    modifier isOwner() virtual override {
        _isOwner();
        _;
    }

    function _isOwner() internal view virtual override {
        // Same as _checkOwner() but using error code instead of a require statement.
        if (owner() != _msgSender()) revert CallerIsNotOwner();
    }
}

@nftculture/nftc-contracts-private/contracts/metadata/v2/art-managers/OffChainArtManager.sol

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

// NFTC Prerelease Contracts
import '../interfaces/AbstractArtManager.sol';

/**
 * @title OffChainArtManager
 * @author @NiftyMike | @NFTCulture
 * @dev This contract exists for consistency with other Art Manager implementations.
 */
abstract contract OffChainArtManager is AbstractArtManager {
    // Tag abstract contract, no internal methods to implement.
}

@nftculture/nftc-contracts-private/contracts/metadata/v2/interfaces/AbstractArtManager.sol

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

// Local References
import '../../../access/v2/OwnableDeferral.sol';
import './IChainNativeArtProducer.sol';
import './IDynamicArt.sol';

// Error Codes
error ArtPieceCountExceeded();
error ArtPieceDoesNotExist();
error ArtPieceAlreadyCreated();
error NullTokenType();

/**
 * @title AbstractArtManager
 * @author @NiftyMike | @NFTCulture
 * @dev A class for managing the datastore that holds Art pieces as either strings or bytes.
 */
abstract contract AbstractArtManager is IDynamicArtV2, IChainNativeArtProducer, OwnableDeferral {
    // Storage for Token Attribute Definitions
    mapping(uint64 => DynamicArtV2) private _artObjects;
    uint64[] private _artPieceTokenTypes;

    uint256 private immutable _maxNumberOfArtPieces;

    constructor(uint256 __maxNumberOfArtPieces) {
        _maxNumberOfArtPieces = __maxNumberOfArtPieces;
    }

    function createArtPieces(
        uint64[] calldata tokenTypes,
        string[] calldata artAssets,
        string[] calldata artAnimations,
        string[] calldata backgrounds
    ) external isOwner {
        require(
            tokenTypes.length == artAssets.length &&
                tokenTypes.length == artAnimations.length &&
                tokenTypes.length == backgrounds.length,
            'Invalid number of assets'
        );

        uint256 idx;
        for (idx = 0; idx < tokenTypes.length; idx++) {
            _createArtPiece(tokenTypes[idx], artAssets[idx], artAnimations[idx], backgrounds[idx]);
        }
    }

    function createArtPiece(
        uint64 tokenType,
        string calldata artAsset,
        string calldata artAnimation,
        string calldata backgroundColor
    ) external isOwner {
        _createArtPiece(tokenType, artAsset, artAnimation, backgroundColor);
    }

    function updateArtPiece(
        uint64 tokenType,
        string calldata artAsset,
        string calldata artAnimation,
        string calldata backgroundColor
    ) external isOwner {
        if (tokenType == 0) revert NullTokenType();
        DynamicArtV2 memory current = _artObjects[tokenType];
        if (current.tokenType == 0) revert ArtPieceDoesNotExist();

        current.tokenType = tokenType;

        if (bytes(artAsset).length > 0) {
            current.encodedArt = artAsset;
        }

        if (bytes(artAnimation).length > 0) {
            current.encodedAnimation = artAnimation;
        }

        if (bytes(backgroundColor).length > 0) {
            current.backgroundColor = backgroundColor;
        }

        _artObjects[tokenType] = current;
    }

    function _createArtPiece(
        uint64 tokenType,
        string calldata artAsset,
        string calldata artAnimation,
        string calldata backgroundColor
    ) internal {
        if (tokenType == 0) revert NullTokenType();
        if (_maxNumberOfArtPieces > 0 && _artPieceTokenTypes.length + 1 > _maxNumberOfArtPieces)
            revert ArtPieceCountExceeded();
        if (_artObjects[tokenType].tokenType > 0) revert ArtPieceAlreadyCreated();

        DynamicArtV2 memory current;
        current.tokenType = tokenType;
        current.encodedArt = artAsset;
        current.encodedAnimation = artAnimation;
        current.backgroundColor = backgroundColor;

        _artObjects[tokenType] = current;
        _artPieceTokenTypes.push(tokenType);
    }

    function getArtObject(uint64 tokenType) external view returns (DynamicArtV2 memory) {
        return _getArtObject(tokenType);
    }

    function _getArtObject(uint64 tokenType) internal view returns (DynamicArtV2 memory) {
        return _artObjects[tokenType];
    }

    function getArtPieceTokenTypes() external view returns (uint64[] memory) {
        return _getArtPieceTokenTypes();
    }

    function _getArtPieceTokenTypes() internal view returns (uint64[] memory) {
        return _artPieceTokenTypes;
    }
}

@nftculture/nftc-contracts-private/contracts/metadata/v2/interfaces/IChainNativeArtProducer.sol

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

/**
 * @title IChainNativeArtProducer
 * @author @NiftyMike | @NFTCulture
 * @dev Super thin interface definition for a contract that
 * produces art in a chain native way.
 */
interface IChainNativeArtProducer {
    /**
     * Given a token descriptor, return a string that can be directly inserted into an
     * NFT metadata attribute such as image.
     *
     * @param tokenType type of the art piece
     * @param extraData extra info that can be used to get the art, if applicable
     */
    function getArtAsString(uint64 tokenType, uint256 extraData) external view returns (string memory);

    /**
     * Given a token descriptor, return a string that can be directly inserted into an
     * NFT metadata attribute such as animation_url.
     *
     * @param tokenType type of the art piece
     * @param extraData extra info that can be used to get the animation, if applicable
     */
    function getAnimationAsString(uint64 tokenType, uint256 extraData) external view returns (string memory);
}

@nftculture/nftc-contracts-private/contracts/metadata/v2/interfaces/IDynamicArt.sol

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

/**
 * @title IDynamicArtV2
 * @author @NFTMike | @NFTCulture
 * @dev Interface that defines the data structure of on-chain artwork.
 *
 * V2 implementation gets rid of the bytes encoding, and instead adds an optional
 * encodedAnimation field.
 */
interface IDynamicArtV2 {
    struct DynamicArtV2 {
        uint64 tokenType;
        string encodedArt;
        string encodedAnimation;
        string backgroundColor;
    }
}

@openzeppelin/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

@openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

contracts/NBART/NFTBookArtBase.sol

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

// NFTC Prerelease Contracts
import '@nftculture/nftc-contracts-private/contracts/access/v2/OwnableDeferralResolution.sol';
import '@nftculture/nftc-contracts-private/contracts/metadata/v2/art-managers/OffChainArtManager.sol';

/**
 * @title NFTBookArtBase
 * @author @NiftyMike | @NFTCulture
 * @dev This contract implements the NFTC IChainNativeArtProducer API, which means
 * it contains logic to return the contents of an NFT image / animation_url field
 * for a given NFT token type.
 *
 * In this particular implementation, the image / animation is stored off-chain. Both IPFS
 * and ARWeave assets are supported, based on what is configured for a given tokenType.
 */
abstract contract NFTBookArtBase is OffChainArtManager, OwnableDeferralResolution {
    function getArtAsString(uint64 tokenType, uint256) external view override returns (string memory) {
        return _getArtObject(tokenType).encodedArt;
    }

    function getAnimationAsString(uint64 tokenType, uint256) external view override returns (string memory) {
        return _getArtObject(tokenType).encodedAnimation;
    }
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 1000,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.