Skip to content

Commit 68808ff

Browse files
authored
add burn function to ERC1155Drop (#264)
add function to ERC1155Drop
1 parent f6dced9 commit 68808ff

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

contracts/base/ERC1155Drop.sol

+48
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,54 @@ contract ERC1155Drop is
155155
return nextTokenIdToLazyMint;
156156
}
157157

158+
/*//////////////////////////////////////////////////////////////
159+
Minting/burning logic
160+
//////////////////////////////////////////////////////////////*/
161+
162+
/**
163+
* @notice Lets an owner or approved operator burn NFTs of the given tokenId.
164+
*
165+
* @param _owner The owner of the NFT to burn.
166+
* @param _tokenId The tokenId of the NFT to burn.
167+
* @param _amount The amount of the NFT to burn.
168+
*/
169+
function burn(
170+
address _owner,
171+
uint256 _tokenId,
172+
uint256 _amount
173+
) external virtual {
174+
address caller = msg.sender;
175+
176+
require(caller == _owner || isApprovedForAll[_owner][caller], "Unapproved caller");
177+
require(balanceOf[_owner][_tokenId] >= _amount, "Not enough tokens owned");
178+
179+
_burn(_owner, _tokenId, _amount);
180+
}
181+
182+
/**
183+
* @notice Lets an owner or approved operator burn NFTs of the given tokenIds.
184+
*
185+
* @param _owner The owner of the NFTs to burn.
186+
* @param _tokenIds The tokenIds of the NFTs to burn.
187+
* @param _amounts The amounts of the NFTs to burn.
188+
*/
189+
function burnBatch(
190+
address _owner,
191+
uint256[] memory _tokenIds,
192+
uint256[] memory _amounts
193+
) external virtual {
194+
address caller = msg.sender;
195+
196+
require(caller == _owner || isApprovedForAll[_owner][caller], "Unapproved caller");
197+
require(_tokenIds.length == _amounts.length, "Length mismatch");
198+
199+
for (uint256 i = 0; i < _tokenIds.length; i += 1) {
200+
require(balanceOf[_owner][_tokenIds[i]] >= _amounts[i], "Not enough tokens owned");
201+
}
202+
203+
_burnBatch(_owner, _tokenIds, _amounts);
204+
}
205+
158206
/*//////////////////////////////////////////////////////////////
159207
ERC165 Logic
160208
//////////////////////////////////////////////////////////////*/

docs/ERC1155Drop.md

+36
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,42 @@ function balanceOfBatch(address[] accounts, uint256[] ids) external view returns
5656
|---|---|---|
5757
| _0 | uint256[] | undefined |
5858

59+
### burn
60+
61+
```solidity
62+
function burn(address _owner, uint256 _tokenId, uint256 _amount) external nonpayable
63+
```
64+
65+
Lets an owner or approved operator burn NFTs of the given tokenId.
66+
67+
68+
69+
#### Parameters
70+
71+
| Name | Type | Description |
72+
|---|---|---|
73+
| _owner | address | The owner of the NFT to burn. |
74+
| _tokenId | uint256 | The tokenId of the NFT to burn. |
75+
| _amount | uint256 | The amount of the NFT to burn. |
76+
77+
### burnBatch
78+
79+
```solidity
80+
function burnBatch(address _owner, uint256[] _tokenIds, uint256[] _amounts) external nonpayable
81+
```
82+
83+
Lets an owner or approved operator burn NFTs of the given tokenIds.
84+
85+
86+
87+
#### Parameters
88+
89+
| Name | Type | Description |
90+
|---|---|---|
91+
| _owner | address | The owner of the NFTs to burn. |
92+
| _tokenIds | uint256[] | The tokenIds of the NFTs to burn. |
93+
| _amounts | uint256[] | The amounts of the NFTs to burn. |
94+
5995
### claim
6096

6197
```solidity

0 commit comments

Comments
 (0)