如何在坚固的情况下在板块上创建每个用户的托管钱包?

发布于 2025-01-28 00:03:13 字数 222 浏览 4 评论 0原文

我是区块链社区的新手,我必须实现一个Web 3.0项目。

在这个项目中,我们有一个ERC20,对于在我们平台上注册的每个用户,我必须创建一个与此用户相关的托管钱包。

用户A希望能够将令牌发送给用户B。

我在Google上没有找到任何具体的东西...所以我可能会朝错误的方向前进。

我的问题是:是否有可能在坚固的情况下使用智能合约进行这种类型的保管钱包,您能解释一下我如何吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留蓝 2025-02-04 00:03:13

在其他方面,您将需要3个智能合约:

  • Factory :这是具有函数decloywallet的智能合约,只能通过某个地址调用部署者地址。这样做的是部署另一个合同的新实例walletproxy,然后将地址存储在映射到UUID字符串中,您可以用来识别链链DB中的每个客户。
  • Walletimplementation :此合同持有您希望钱包执行的操作,例如TransfererC20,Stake,Stake,Swap等,并且可以是任何事物。这将是一份合同,您总是可以交换并使用另一个具有更新功能的合同,但是请小心您需要了解升级如何在智能合约中工作和设计版本1。该合同只能为创建的每个新版本部署一次。
  • WalletProxy :这是每次通过在factory.sol.sol.sol合同中调用DeployWallet函数创建新钱包时所部署的合同,仅由某个地址call。它是每个用户的钱包,它只是一份代理合同,它使用delegatecall从Walletimplentation调用功能,因此将来,如果有任何更新,例如Walletimplentation v2 v2,它将始终可以访问它。棘手的部分也是以这样的方式编写它,使得只有某个地址可以调用所有已部署的钱包代理合同。

参考合同:

我在被问及如何使用智能合约创建托管钱包时创建了以下合同。

  • walletimplementation.sol 。

​youtube.com/watch?v=xxlWrumakvs“ rel =“ nofollow noreferrer”>实时会话我使用上述模式建立了一个简单的交换。您也可以在此处浏览完整的代码库 https://github.com/celotas/celotas/cxchange

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文