0

I am new to solidity development and most likely I misunderstand something in the development logic for ethereum.

I want every user of my site to be able to create a smart contract with parameters that are unique for that user, such as a name, and some unique numeric values ​​that the user enters into a form on the site. And then only that user was able to interact with that smart contract.

It seemed to me that it works like this: the data entered in the form is inserted into the uncompiled version of the smart contract, the smart contract is compiled and then sent to the blockchain. But, probably, I am mistaken, because I cannot find any ready-made solutions for such a case, or at least a description of the logic of this process.

Could you point me in which direction should I look? What is the correct way to write a smart contract in my situation? And is it even possible to create unique smart contracts for each individual user on the site, compile them and send them to the blockchain?

1 Answer 1

1

Since blockchain is somewhat new compared to other technologies for custom solutions that you've stated, it'll be very hard to find ready made solutions for this exact problem you face. You'll certainly have to choose a more custom approach.

Another issue with your approach is every user having their own contract. I'm assuming you wan't to create a new smart contract for each user that signs up for your application. This would be very expensive since each time you upload a smart contract to the blockchain, needs to be payed with in Ether since you are adding more Bytecode onto the chain.

Another issue is deploying a workload to compile your smart contracts for each user & also deploy them to a running node. Depending on your user traffic this can really become expensive if you need a powerful AWS EC2 Instance or Droplet to handle all the complication of smart contracts.

My advice would be to create a central smart contract that keeps track of all your users & their data.

Following example - **NOT PROD READY**

pragma solidity ^0.8.13;

contract APIUsers {
    event CreatedUser();
    // UserId -> Payload
    // Mapping that stores all the user ids & their payloads;
    mapping(string => string) public users;

    function createUser(string memory _userid, string memory _payload) external {
        users[_userid] = _payload;
    }

    // returns all the user details such as [username, bio, zip, etc.....]
    function getUser(string memory _userid) public view returns (string memory payload) {
        return users[_userid];
    }
}

Simply you can store the Users UUID (created on your backend or frontend) as a key for the mapping & have a stringify JSON payload as the value of the mapping, this way when you fetch the data from the chain you can serialize that payload into an object to represent on the front end.

Hope this helps!

1
  • Thanks for the advice! Your version looks nice, but I'm probably too newbie to understand some parts of it. However, I find the idea of ​​using mapping very useful and potentially beneficial to me. I will try to create one smart contract instead of individual ones, and it will be the same for all users, and the difference in data will work through mapping, something like (address => string data). Maybe this will work for me, if not I will try to recreate your idea with one main smart contract that controls the others.
    – Misso NYk
    Nov 13, 2022 at 11:22

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.