0

I have the mintable token code working fine. Now I would like to add the ability for the tokens to 'remember' when/why they were minted, such as,

0-100 group 1, 101-300 group 2, 301-1000 group 3, etc...

I had the idea of using another mapping, but once the tokens get transfered around, they need to remember what group they are in.

Thank You!

1 Answer 1

0

I don't really get the problem you are having. You already answered your question yourself. Add a mapping(uint => uint) mintGroup or whatever variable type you need to map the specific tokenId to the group. Transfering the token does not change its id and thus will not change the mapping.

You could also add it as a variable in the token itself but handling those is really uncomfortable in comparison to using mapping.

EDIT: Beware that a token standard like ERC721 is needed to accomplish that. ERC20 standard will not work because every token is the same and therefore cannot store information about the reason of minting it.

5
  • But how do I attach the id in the first place?
    – Barrard
    Commented Mar 5, 2018 at 12:07
  • If you want to mint tokens, you should have already included a function to mint them. You will call it like uint tokenId = _createToken(address(this)); After that call you have the id and assign it to the mapping: mintGroup[tokenId] = 1 Commented Mar 5, 2018 at 12:15
  • So I have. function mint(address to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply = totalSupply_.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } How would I make 100 tokens with an id of 1?. –
    – Barrard
    Commented Mar 5, 2018 at 12:32
  • Okay so, as I see know, you use a ERC20 type token. What you want to accomplish will not work with that. ERC20 token are ALL the same, so they cannot store information like the reason for minting them. What you want will require a ERC721 token which makes every single token unique. You will have to change your code accordingly to support ERC721 Commented Mar 5, 2018 at 12:33
  • Great thank you Fabian! I had overlooked this token. ERC721 looks like the right token for the job.
    – Barrard
    Commented Mar 5, 2018 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.