[Working draft] New extension for ERC1155

Hi everyone,

I’m here for propose my idea to Ethereum Magicians community, redirected by a kind user of the Open Zeppelin community. I hope I can explain myself well and also some guidance if my proposal is really liked and can become an official standard.

I have been developing 2 extensions for ERC1155 as a personal purpose, but after discussing it with several developers I have been proposed to present it as an official extension.

I saw that the ERC1155 standard does not have the possibility to approve tokens by id or amounts as for example in ERC20. So, to create more security to my clients, I have designed the following code to avoid my smart contract to be approved for all ids, later I thought to develop the same but with amounts.

Code and explanations are here: GitHub - ivanmmurciaua/ERC1155ApprovalByAmount: A draft to do a safe approval by individual amounts by id for ERC1155 standard

It would be a pleasure to humbly contribute to this great community of developers.

Feel free to answer me and discuss with me.

Greetings from Spain,
Iván M.M.

3 Likes

I think approving a specific amount for a specific id would be good and consistent with the erc20 usage patterns. I second this proposal

1 Like

Hi @dadabit . Thanks for the feedback and support. Hope other users second my proposal like you. Best regards.

Hey there. It’s not a bad idea when we see ERC1155 as a collection of fungibles.

ERC1155ApprovalById:

I think the ApprovalById is redundant, you can simply approve amount to MAX_INT.
→ I would totally remove ERC1155ApprovalById

ERC1155ApprovalByAmount

Also I don’t think safe(/Batch)TransferFromByAmount are necessary.

safe(Batch)TransferFrom are already enough, you simply have to override them so they check for ApprovalForAll OR allowance.
This also makes your extensions smaller, which increases the likeliness to appeal to people.
Big extensions are bloating code that is already big enough.

In term of API, I would also try to keep it more consistent:

  • if you use “setAllowance()” then use “getAllowance()”

  • personally, I would prefer it more consistent with the erc20 api (approve(spender, tokenId, amount) & allowance(owner, spender, tokenId)) but that’s just a preference.

1 Like

Hey @dievardump. Thanks for reply and feedback mate.

I’d like to go point by point:

ERC1155ApprovalById:
Only for have it this version, I created a branch which is unimplemented in main

ERC1155ApprovalByAmount:
I fit terms of my API to ERC-20 like you said: Now the names are 100% like ERC-20, approve, allowance and mapping _allowances.

But I have one question regarding what you said about safe(Batch)TransferFrom. I understood that if someone wants to use the ByAmount extension, they would have to override the original ERC1155 safeTransferFrom function. Is this correct?

If changes only the condition, I would understand it, but it should be noted that the line where the amount transferred is substracted of the operator allowance… wouldn’t it be a bit dangerous to leave that to the free code of a programmer who doesn’t know the extension?

I don’t quite understand/see how to implement this functionality without my extension becoming heavy and repetitive.

Thanks for all, look forward to your answer.