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;
/**
* Single-file ERC1155 contract with fixed token ID (1) and batch airdrop support.
* No external imports, suitable for open-source deployment.
*/
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);
// ============================
// Constructor
// ============================
constructor() {
owner = msg.sender;
name = "My1155NFT";
symbol = "MNFT";
_baseURI = "ipfs://ipfs/QmV7gdtEvxmB7FaBmy855B1JjcD72nqABw5ZFXtZ1hFzTu";
}
// ============================
// Modifiers
// ============================
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
// ============================
// ERC1155 core functions
// ============================
function balanceOf(address account, uint256 id) public view returns (uint256) {
require(account != address(0), "Zero address");
return _balances[id][account];
}
function balanceOfBatch(address[] memory accounts, uint256[] memory ids) public 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] = balanceOf(accounts[i], ids[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) public 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) public view returns (string memory) {
return _baseURI;
}
function setBaseURI(string memory newuri) external onlyOwner {
_baseURI = newuri;
emit URI(newuri, TOKEN_ID);
}
// ============================
// Ownership management
// ============================
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Zero address");
owner = newOwner;
}
}
Submitted on: 2025-10-16 11:36:19
Comments
Log in to comment.
No comments yet.