Build Smart Contract Extensions for a Collection
You can build everything on top of an ITEM Collection via the Extension. Here you can find a simple example demonstrating the code:
1
pragma solidity ^0.7.4;
2
3
contract ExtensionExample {
4
address private _collection;
5
6
address private _owner;
7
8
constructor() {
9
_owner = msg.sender;
10
}
11
12
function owner() public view returns(address) {
13
return _owner;
14
}
15
16
function collection() public view returns(address) {
17
return _collection;
18
}
19
20
modifier ownerOnly {
21
require(msg.sender == _owner, "Bad boy!");
22
_;
23
}
24
25
function init() public {
26
require(_collection == address(0), "Init already called!");
27
_collection = msg.sender;
28
}
29
30
function setOwner(address newOwner) public ownerOnly {
31
_owner = newOwner;
32
}
33
34
function mint(uint256 amount, string memory tokenName, string memory tokenSymbol, string memory objectUri, bool editable) public ownerOnly {
35
(,address tokenAddress) = IEthItem(_collection).mint(amount, tokenName, tokenSymbol, objectUri, editable);
36
IERC20 token = IERC20(tokenAddress);
37
token.transfer(msg.sender, token.balanceOf(address(this)));
38
}
39
}
40
41
interface IEthItem {
42
function mint(uint256 amount, string calldata tokenName, string calldata tokenSymbol, string calldata objectUri, bool editable) external returns (uint256 objectId, address tokenAddress);
43
}
44
45
interface IERC20 {
46
function balanceOf(address account) external view returns (uint256);
47
function transfer(address recipient, uint256 amount) external returns (bool);
48
}
Copied!
Example of an Extension that enables the transfer of Ownership. The actual owner can transfer the Collection Ownership to someone else. Only the current owner can call the mint(...) method of the extension and the “mint(...)” method of the Collection.
Copy link