Page cover

Genesis and NFT Contract

Genesis and Genesis NFT Contract

Solidity contract with the specified features on the Binance Smart Chain involves integrating an ERC-20 token with additional functionalities such as transaction fees, a reward distribution system, NFT minting capabilities, and the option to renounce ownership. Below is an illustrative example encapsulating these requirements. This contract combines the ERC-20 token features with an integrated ERC-721 (NFT) contract for minting in-game items, alongside mechanisms for transaction fees and reward distribution. This example aims to provide a conceptual foundation; real-world deployment necessitates rigorous testing and potentially a professional audit.

Token Contract

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract Genesis is ERC20, ERC20Burnable, Ownable, ReentrancyGuard {
    uint256 public constant TOTAL_SUPPLY = 42_000_000 * (10 ** 18);
    uint256 private constant BURN_RATE = 50; // 0.5%
    uint256 private constant REWARD_RATE = 50; // 0.5%
    mapping(address => uint256) private _rewards;
    mapping(address => bool) public isExcludedFromFees;

    constructor() ERC20("Genesis", "GEN") {
        _mint(msg.sender, TOTAL_SUPPLY);
        isExcludedFromFees[address(this)] = true;
        isExcludedFromFees[msg.sender] = true;
    }

    function _transfer(address sender, address recipient, uint256 amount) internal override {
        uint256 fees = 0;
        if (!isExcludedFromFees[sender] && !isExcludedFromFees[recipient]) {
            uint256 burnAmount = (amount * BURN_RATE) / 10000;
            uint256 rewardAmount = (amount * REWARD_RATE) / 10000;
            fees = burnAmount + rewardAmount;
            _burn(sender, burnAmount);
            _rewards[address(this)] += rewardAmount;
        }
        super._transfer(sender, recipient, amount - fees);
    }

    function claimRewards() public nonReentrant {
        uint256 reward = _rewards[msg.sender];
        require(reward > 0, "Genesis: No rewards to claim");
        _rewards[msg.sender] = 0;
        _transfer(address(this), msg.sender, reward);
    }

    function renounceOwnership() public override onlyOwner {
        revert("Genesis: renouncing ownership is disabled");
    }
}

contract GenesisNFT is ERC721Enumerable, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIdCounter;
    Genesis private _genesisToken;

    constructor(Genesis genesisToken) ERC721("GenesisNFT", "GENN") {
        _genesisToken = genesisToken;
    }

    function safeMint(address to) public onlyOwner {
        _tokenIdCounter.increment();
        _safeMint(to, _tokenIdCounter.current());
    }

    // Optional: Override `_beforeTokenTransfer` if you want to integrate with the Genesis token logic,
    // such as rewarding NFT transactions or excluding NFT transactions from certain token functionalities.
}

Key Features and Considerations:

  • ERC-20 Token with Fees: Implements a 0.5% burn rate and a 0.5% reward distribution on transactions, excluding specified addresses to prevent unnecessary fee deductions (e.g., when transferring between contract-owned addresses).

  • Reward Claiming: Allows users to claim accumulated rewards, ensuring non-reentrancy for security against potential reentrancy attacks.

  • Renounce Ownership Disabled: For security purposes and to maintain control over the contract's functionalities, renouncing ownership is intentionally disabled. Once everything is finalized and 100% complete the contract will be renounced.

  • NFT Minting: The GenesisNFT contract allows for the minting of NFTs, with a link back to the Genesis token contract. This could be used for in-game items or other utilities within the ecosystem.

  • Security Features: Utilizes Ownable for access control and ReentrancyGuard to prevent reentrancy attacks, especially important in functions that involve token transfers based on external calls or state changes.

Deployment and Management:

  • Testing: Extensively testing of the contract in various scenarios on test networks will ensure all functionalities work as expected without unintended behaviors, especially concerning fee deductions, reward distribution, and NFT minting.

  • Optimization: Gas costs and optimizing where possible, particularly for functions that will be called frequently by users. Although the Binance chain has cheap gas, we want to ensure the bect optimization for the lowest fees possible.

  • Compliance and Legal: We will ensure the contract adheres to the regulations of jurisdictions where it will be deployed or used, especially concerning tokenomics and NFTs.

This contract serves as a conceptual starting point, transparency and will require further customized thorough testing to ensure it meets specific project needs and security standards.

Last updated

Was this helpful?