2

I'm new in the blockchain community, and i have to realize a web 3.0 project.

In this project, we have an ERC20, and for each user who sign up on our platform, I have to create a custodial wallet attached to this user.

User A want to be able to send tokens to User B.

I didn't find something concrete on google... so I'm maybe going in the wrong direction.

My question is: Is it possible to do that type of custodial wallet with smart contract in Solidity, and can you explain me how ?

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

1

In other to achieve this you will need 3 smart contracts:

  • Factory: This is the smart contract that has a function deployWallet that can only be called by a certain address, most likely the deployer address. What this does is deploy a new instance of another contract WalletProxy and store the address in a mapping to a UUID string which you use to identify each customer in your off-chain DB.
  • WalletImplementation: This contract holds the action you want your wallets to perform, e.g transferERC20, stake, swap, etc., and can be anything. It's going to be a contract you can always swap out and use another one with a more updated function, but be careful you need to understand how upgrades work in smart contracts and design Version 1 well. This contract will only be deployed once for every new version created.
  • WalletProxy: This is the contract you deploy every time a new wallet is created by calling the deployWallet function in the Factory.sol contract, only callable by a certain address. It serves as a wallet for each user and it's only a proxy contract that uses delegatecall to call functions from WalletImplementation, so in the future, if there is any update like WalletImplementation V2 it will always have access to it. The tricky part is also writing it in such a way that only a certain address can call all of the deployed wallet proxy contracts.

Reference Contracts:

I created the following contracts for the same demonstration purposes when asked how to create a custodian wallet using smart contracts.

I also did a live session where I built a simple exchange using the pattern described above. You can also go through the full codebase here https://github.com/CeloTAs/cXchange

Alofe Oluwafemi
  • 111
  • 4
  • 16