0

I'm playing around with programmatically forming DAOs. Essentially I want to create a frontend users can come to, type in a name, click a button and deploy a smart contract. I'd like to display a list of smart contracts that user has previously deployed so I'll need some way to query for contracts owned by that user's wallet address.

Is there a way to relate smart contracts to a wallet address in a way that's queryable?

Example:

contract CoolDAO {
    string name;
    address public owner;

    constructor(string _name) payable {
        name = _name;
        owner = msg.sender;
    }

    function getName() public view returns (string memory) {
        return name;
    }
}

Users should be able to:

  1. Deploy this contract with a particular name
  2. See a list of all the contracts they've previously deployed.

My first thought is that I would create an NFT collection representing ownership of the contracts - then when the user deploys a contract, I'd mint an NFT for them with an attribute that points to that contract's address. Then if I wanted to know what contracts that user owned, I could query for any NFTs they own from that collection. (Essentially I'd be using an NFT as a many-to-many table)

Is there a more straightforward approach to handle this?

2
  • Why not just store the info to a regular database? Jan 12 at 20:03
  • I probably will but I'd rather not rely on my own database as the source of truth but rather as a cache. I want to be confident that if anything went wrong with my database, I'd be able to repopulate it by reading from the blockchain
    – user91324
    Jan 12 at 20:46

1 Answer 1

0

Since you want to use the blockchain to store the information, I recommend a contract factory pattern.

So you should have one contract factory contract. That contract acts as a factory: it creates contracts upon demand. At the same time, it keeps track of who has deployed what contract.

Whenever you need information about who has deployed what, you just query the factory for the information.

Your Answer

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

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