# argent钱包源码-（二）创建钱包流程

By [daxiong](https://paragraph.com/@daxiong) · 2022-10-05

---

一、创建钱包的流程：

1、调用walletFactory的createCounterfactualWallet方法创建钱包；

2、通过输入盐进行加工，生成唯一的盐，创建钱包，得到create2钱包地址；

3、进行管理员验签，调用者必须是walletFactory的管理员；

4、然后初始化创建的钱包，设置钱包主人和模块合约；

5、如果设置了回退token(refundToken)和回退地址(refundAddress)，那么调用钱包合约的invoke方法将钱包的钱回退（前提是该钱包地址必须提前转入资产）

详细流程图和合约方法梳理如下：

![create wallet](https://storage.googleapis.com/papyrus_images/17b2d66279cf3737a3a168f1712f1f9c790c9bff44b3beb000484dc19dccf3ab.png)

create wallet

二、提前转入资产

1、由于钱包地址是通过盐+create2创建的，因此钱包地址可以通过相应的规则提前知晓；

2、walletFactory合约已经提供了提前获取合约地址的方法**_getAddressForCounterfactualWallet_** ，因此我们通过调用该方法可以提前获取地址，并且创建钱包之前注入相应的资产。

---

*Originally published on [daxiong](https://paragraph.com/@daxiong/argent-3)*
