Using moralis for user logins

Hey everyone i have an issue that i would be great full if anyone could help with. Basically i am creating a multisig wallet. I am using a factory contract which allows new users to come on and create new wallet instances. However i am facing a problem with logins.

So with a multisig wallet there are multiple owners. I want to create a login in system such that whenver a user logs on there are faced with all of there existing wallets if any and also the option to create a new wallet.

So my question is this. Is there any way using morlais to keep track of all contract instances and then associate that instance with the address’ who are classified as the wallet owners. My original plan was to store user accounts in a mongodb and do it this way but i want quick results so am seeking a quicker option and morlais seems like ot could do the job. Even though i probably will at some point in the future imolement mongodb also

I know moralis keeps track of user accounts obviously but i just meed to figure out a way to associate contract instances with user accouns that are owners of that instamce.

Is it possible to do this with moralis. Im not looking for anyone to try throw up any code. I am only seeking genesal guidence about a good way to go about this using moralis. Thank you

Evan

Hi,
Can you try to explain it with an example? It is not clear for me what you need.

1 Like

@cryptokid sure. Gimme 10 mins just have to get back to my computer

hey @cryptokid. Sorry for taking so long to reply i was out for the whole day. Ok so i will break down exactly what im thinking so that you can understand better.

So as i was saying i have developed a multisig wallet that allows the owners to deposit, withdraw and transfer ethereum and other ERC20 tokens. And for transfers or withdrawals to get accepted a majority consensus between all of the wallet owners must be achieved in order for the transaction to be executed.

This is a ll fine. However i have now finished the development of my wallet and everything looks and work brialliantly. However i am now faced with an issue i had no even throught about when initially builiding the app out. There is currently only contract instance that gets deployed to the network (be it a local dev chain or to testnet etc). This means that the wallet owners can of open the dapp on their won browser and view the wallet and use it. However there is nothing from stopping another user who is NOT a wallet owner from opening the app on their own browser either. Although my Dapp will realise that they are not an owner, preventing them from being able to use the wallet, they will still be able to see the account which belongs to other people.

So what i am planning to do is to develop my own login system. The root of this login in system will be to modify my multisig smart contract to be a factory contract. In other words my main multisig contract will act as a child contract and below it i will write a new factory contract. I will then deploy this factory contract instead. The main functionality of the factory contract is that when deployed i will be able to call a function called

function createNewMultiSigWallet() public .......

for example that will create a new instance of my multisig contract and append it to an on-chain storage array. This method of deploying contract instance is used widely in the defi spaces one example being uniswap which uses a factory contract to make new liquidity pools anytime some user wants to create one. So this is great i now have a way for users to open my wallet user interface or dapp and create new wallet instances which they will be the owner of and then they can add other signaories as needed.

The problem is that i need a way to keep track of my user data. For example if a user logs on how can my dapp figure out if that user has previously created any wallets and if so how can my dapp fetch this data and display to the user all of their wallets (which are the contratc instances that they were the deployer of.)

This challenge has led me down two routes. The first is to set up a mongoDB database in which i can append user data to everytime a new user deploys a new contract instance using the factory contarct. This would work where i would store the contract address in the mondoDB and link that contractb instance to both the user who deployed it and other wallet owners of that instance. Thus when the owneer initially logs on to the Dapp i can simply use their address and query the database to see if that address maps to a contract instance. If it does i will return all instances so that the user can load it in using

var contractInstance = await new web3.eth.Contract(abi, contractInstanceChoosenByUser)

The only problem is it will most likley take me a week or more of constant coding to set up the mongo DB and link it to my front end. Mostly because i have only used mongoDB once before for an application that a blockhain Dapp thus i would have to also spend time increasing my knowledge. I do not mind this and at some later stage i will definitely return to this project and implement a mongoDB as i think it would add an extra level of complexity to my Dapp

So the other alternative i was pondering was to use Moralis. Although i have never used it before i have been watching lots of vides and i constantly watch ivans interviews on the channel as i am very interested in the tech. The main reason i have never used it before is because i prefer building this from scracth as it is more rewarding rather than one liners. Howeevr i do now want to use it (if possible to solve the issue i am describing above). That is why i have come to this forum to ask would it be possible to implement this.

Basically as i was saying in my post above, i know that you can use moralis to authenticate users and append all logged users to a users DB. However keeping track of users is not enough for me as i need an extra layer of checking that is able to map a user to a contratc instance. So is there a way for me to keep track of what address deployed what contracts using moralis. Because if there is i could finish my dapp in a few hours rather than having to spend ages inegrating a mongoDB.

I hope now i have made it a little clearer about exactly what i am after. Again i am only seeking general guidance and validation that this is possible using moraliis to save me starting to use the tech and then to realise after a few hours that what i want to achieve is able to be done. The rest i can handle myself. I want to appreciate you for atking the time to read my post. Thank you

Regards,
Evam

The solution that I’m thinking now is to use an event when the contract is created, that event will include all the addresses that participate in that multi sig, and using Moralis you can sync all those events in a database with a plugin, and after that you only have to do a query in the existing events database table.
https://docs.moralis.io/moralis-server/automatic-transaction-sync/smart-contract-events#sync-and-watch-contract-events

1 Like

ahhhh brilliant. Thank you so much that is actually very clever i had not thought of using an event. that seems way easier than having to implement a mongoDB everything will be onchain for me. Thank you so much i will look into this a play around with it will let you know how i get on. Thank you very much @cryptokid

1 Like