Token Burning

Burn Contract with ERC721 Confirmation

Data Flow: Token Burning Procedure:

  1. User initiates the burn mechanism, defining both the quantity and specific ID of the ERC1155 tokens designated for destruction.

  2. The specified ERC1155 tokens undergo removal from the user's possession.

  3. Subsequently, an ERC721 token gets minted, bearing the proof-of-burn, and then gets allocated to the user's address.

Proof-of-Burn via ERC721:

  1. The minted ERC721 token encompasses a metadata payload that encapsulates the entirety of the burn event. This includes:

    • The exact quantity of the ERC1155 tokens annihilated.

    • The precise ID attached to the ERC1155 tokens.

    • A timestamp marking the event.

    • The initiator's Ethereum address.

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract EnhancedBurnContract is ERC721Enumerable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    IERC1155 public erc1155Token;

    // Metadata URI for ERC721 token
    mapping(uint256 => string) private _tokenURIs;

    constructor(address _erc1155Token) ERC721("ProofOfBurnToken", "PBURN") {
        erc1155Token = IERC1155(_erc1155Token);
    }

    function burnTokensAndGetProof(uint256 erc1155TokenId, uint256 amount) public returns (uint256) {
        erc1155Token.burn(msg.sender, erc1155TokenId, amount);
        
        _tokenIds.increment();
        uint256 newTokenId = _tokenIds.current();
        _mint(msg.sender, newTokenId);
        _setTokenURI(newTokenId, generateMetadataURI(erc1155TokenId, amount));

        return newTokenId;
    }

    function generateMetadataURI(uint256 erc1155TokenId, uint256 amount) internal view returns (string memory) {
        // This is a placeholder. In a real-world scenario, the function would generate or fetch a URI, possibly pointing to IPFS or another decentralized storage solution, containing the relevant metadata.
        return string(abi.encodePacked("https://tokenmetadata.domain/path/", toString(erc1155TokenId), "_", toString(amount)));
    }

    function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
        _tokenURIs[tokenId] = _tokenURI;
    }

    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
        return _tokenURIs[tokenId];
    }

    function toString(uint256 value) internal pure returns (string memory) {
        // Convert uint256 to string
        return ...;  // Placeholder
    }
}

Functions:

burnTokensAndGetProof:

  • Objective: Authorize users to eradicate their ERC1155 tokens and subsequently obtain an ERC721 token as a proof-of-burn.

  • Input Parameters:

    1. erc1155TokenId: ERC1155 token's distinctive identifier that's set for burn.

    2. amount: Quantity of ERC1155 tokens marked for annihilation.

  • Output: Deploys an ERC721 token and registers it under the user's address.

  • Internal Actions: The function begins by torching the specified ERC1155 tokens from the user's stash. It then mints a unique ERC721 token, links it with a distinct URI representing the burn details, and finally allocates it to the user.

Last updated

Logo