Is it possible to deploy a contract with metatransaction?

I have successfully implemented metatransactions via Defender, but our application wants to deploy a new contract for each user that is onboarded. We are wondering if there is a way for users to sign a transaction to deploy a contract, and relay it to our forwarder? Thanks!

:computer: Environment


:1234: Code to reproduce

Hey @Richard_Zhang! I believe it's not doable without throwing another contract into the mix. You can have a generic Factory contract that calls CREATE (or CREATE2 if you prefer, see Create2.sol from OpenZeppelin Contracts) with whatever payload it receives, and have your users sign a meta-tx that calls the Factory contract with the creation code.

However, if your plan is that every user creates the same contract, I'd suggest embedding the contract creation code within the factory itself, so each meta-tx is much cheaper since it doesn't have to carry the contract creation code. Or even better, consider using minimal proxies!

Hello @spalladino. Our design is creating an ERC1155 contract for every user who logs onto our dapp (sort of like a wallet). Could this be done whereFactory stores erc1155 creation code, all wallet data for EACH wallet, and also have upgradeability for all ERC1155 wallets? Thanks!

Also, a radical alternative design would be to just use 1 ERC1155 contract that stores ALL user data for our platform, instead of a factory that deploys a new contract for each user. Is it scalable or are there any security issues or larger gas/storage costs to that?

You probably want to look into beacon proxies: you keep a single instance of the 1155 code, deploy a beacon that points to it, and for each new user you create a new beacon proxy. When you need to upgrade, you just update the beacon to a new 1155 implementation.

@ericglau spoke about beacon proxies in the community call yesterday, you can check out the recording here.

Without knowing the details, I'd say this is at least as scalable as having one 1155 per user. The main advantage of a contract per user is that you keep each user's stuff more isolated. The main advantage of having it centralized is that operations are usually easier (you only need to account for a single contract). Up to you!

Sounds good! Maybe from a more design / user experience, I feel like giving users their own contract seems more conventional. Plus these NFTs could plug into opensea, where each user could have their own collection!

Thanks again @spalladino, saved my day!

1 Like