0

Hello StackExchange 👋

I'm working on my first Ethereum learning project (an ERC721 marketplace that generates tokens based on user input), wrote a couple of untested contracts and am now looking to integrate those in my app.

This is how I envision the process:

  • User inputs a sentence in app
  • A token is minted by the contract owner (me)
  • A "Sale" contract is created for this user
  • User purchases the token from the sale contract

Now, there are several things that bug me with with what I came up with:

  1. Because of the multi-contract approach, it seems that the transactional aspect of Ethereum is a bit broken: a token could be generated while something would fail during the sale. A malicious user could make me generate an infinite number of tokens without having the funds to pay for them.
  2. The JS implementations I looked at sign user transactions client-side. For my case, this would mean that I would generate the token server-side and return a payload with amount and Sale contract ID. But in that case, the user could interrupt the flow at any moment by simply reloading the page, leaving me with a bunch of unsellable tokens.

The solution I was going for:

Accepting that the full transaction happens in two times, if I can sign transaction from the user and send it to my server. Also, I coud maybe create the contract before the token then perform checks on user balance, and only at that moment mint the token.

As I said at the beginning, I'm super new to blockchain in general and take this project as an opportunity to understand things. Does the general plan makes sense? Do you have examples of such implementations in node.js, with web3.js or Infura?

Thanks a lot!

2
  • Why are you creating the token? Isn't it better to make the user pay for it? You can sign an authorization message from the backend and let the user submit that message to the creation. Why one Sale contract for each user? Isn't it better to have a single sale contract for every token created? If I've to start a project from scratch I'd use Hardhat's boilerplate project as a template. If you search github you should find similar projects with your favorite frameworks combination, angular, react, truffle, ect. – Ismael Jun 4 at 1:08
  • Thanks for the link, it's super useful! I was creating the token because the tokenURI is generated on the fly, so it seemed simpler to have control over everything before passing a Sale contract to the user. I also like to make the user only pay a flat-rate price and let me take care of everything else. For the Sale contract: yeah it's supposed to be one per generated token, not per user. I'll edit my question with more information – hypervillain Jun 4 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.