Description:
Multi-token contract following ERC1155 standard, supporting both fungible and non-fungible tokens.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title NFT1155Airdrop
* @notice Single-file ERC1155-like contract for a single token ID (1).
* @dev Supports minting, batch airdrop, and owner-controlled metadata updates.
* No external dependencies, suitable for open-source release.
*/
contract NFT1155Airdrop {
// ============================
// Basic ERC1155 state
// ============================
mapping(uint256 => mapping(address => uint256)) private _balances;
mapping(address => mapping(address => bool)) private _operatorApprovals;
string public name;
string public symbol;
string private _baseURI;
address public owner;
uint256 public constant TOKEN_ID = 1;
// ============================
// Events
// ============================
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event NameUpdated(string oldName, string newName);
event SymbolUpdated(string oldSymbol, string newSymbol);
event BaseURIUpdated(string oldURI, string newURI);
// ============================
// Constructor
// ============================
constructor() {
owner = msg.sender;
name = "My1155NFT";
symbol = "MNFT";
_baseURI = "ipfs://ipfs/QmV7gdtEvxmB7FaBmy855B1JjcD72nqABw5ZFXtZ1hFzTu";
}
// ============================
// Modifiers
// ============================
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
// ============================
// ERC1155 core
// ============================
function balanceOf(address account, uint256 id) public view returns (uint256) {
require(account != address(0), "Zero address");
return _balances[id][account];
}
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory)
{
require(accounts.length == ids.length, "Length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; i++) {
batchBalances[i] = _balances[ids[i]][accounts[i]];
}
return batchBalances;
}
function setApprovalForAll(address operator, bool approved) external {
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
function isApprovedForAll(address account, address operator) external view returns (bool) {
return _operatorApprovals[account][operator];
}
// ============================
// Minting & Airdrop
// ============================
function mint(address to, uint256 amount) external onlyOwner {
require(to != address(0), "Zero address");
_balances[TOKEN_ID][to] += amount;
emit TransferSingle(msg.sender, address(0), to, TOKEN_ID, amount);
}
function airdrop(address[] calldata recipients, uint256 amount) external onlyOwner {
for (uint256 i = 0; i < recipients.length; i++) {
address to = recipients[i];
require(to != address(0), "Zero address");
_balances[TOKEN_ID][to] += amount;
emit TransferSingle(msg.sender, address(0), to, TOKEN_ID, amount);
}
}
// ============================
// Metadata
// ============================
function uri(uint256) external view returns (string memory) {
return string(abi.encodePacked(_baseURI, "/1.json"));
}
function setBaseURI(string memory newURI) external onlyOwner {
emit BaseURIUpdated(_baseURI, newURI);
_baseURI = newURI;
emit URI(newURI, TOKEN_ID);
}
function setName(string memory newName) external onlyOwner {
emit NameUpdated(name, newName);
name = newName;
}
function setSymbol(string memory newSymbol) external onlyOwner {
emit SymbolUpdated(symbol, newSymbol);
symbol = newSymbol;
}
// ============================
// Ownership management
// ============================
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Zero address");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
Submitted on: 2025-10-16 11:36:27
Comments
Log in to comment.
No comments yet.