I'm working with an app where different users can create their own ERC721 tokens by passing token, symbol total supply etc. Currently, the code is creating the token, but it has common name only.
pragma solidity ^0.5.0;
import "./token/ERC721/ERC721Full.sol";
import "./drafts/Counters.sol";
contract MyContract is ERC721Full {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721Full("MYToken", "MYT") public {
}
function mint(address player) public returns (uint256) {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);
return newItemId;
}
}
How to create tokens with different name and symbol for each user? and mint to their account?
Do I need to deploy a smart contract per user? if so, the complexity will be increased by time. And is there any best practice available.
Best Answer
You can use a clone factory smart contract to do so. https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol
An example of your ERC721 factory would be
template will be the address of your ERC721 contract.
The new _address will be the address of new ERC721 token with the myName and mySymbol. The owner of new ERC721 token will be msg.sender. You can pass more variable to set function as per your requirements.
Your constructor function of the ERC721 contract should ideally be empty and should have a set function that will set myName and mySymbol.