How do you include royalties in a normal ERC1155 contract?
Something like this:
// Import 1155 token contract from Openzeppelin
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
contract NFTContract is ERC1155, Ownable {
uint256 public constant ARTWORK = 0;
uint256 public constant PHOTO = 1;
constructor() ERC1155("https://wzh58eid3jnd.usemoralis.com/{id}.json") {
_mint(msg.sender, ARTWORK, 1, "");
_mint(msg.sender, PHOTO, 2, "");
}
function mint( address to, uint256 id, uint256 amount) public onlyOwner {
_mint(to, id, amount, "");
}
function burn( address from, uint256 id, uint256 amount) public {
require(msg.sender == from);
_burn(from, id, amount);
}
}```
Best Answer
Short Answer:
Long Answer
The NFT World is divided when it comes to Royalties.
As you can see here, OpenSea seems to do this off-chain by allowing you to include the royalty information in your metadata.
Rarible has a seperate smart contract called the Royalties Registry that is used to track the royalties of each NFT.
Various internet sources suggest to add custom code into your
transferFrom()
functions. However I would advise against this as mentioned in EIP-2981Thankfully, this lack of conformity across the NFT space will hopefully change now that EIP-2981: NFT Royalty Standard has recently been approved. It is still early days but some marketplaces like Mintable have already implemented this and there has been public support for OpenSea to do the same.
Given that EIP-2981 is not yet supported by the bigger marketplaces my advice to you would be to:
Here is an example of how you can support both EIP-2981 and OpenSea given the information you have provided. I have copied some code from this repo.
For the contract metadata for OpenSea it might look something like this: