ZkSync 文档指出,为了创建一个新帐户,必须从一个现有的ZkSync帐户存入一个不存在的ZkSync帐户。
但是,用于进行存款的方法已经将一个ZkSync帐户地址作为参数来指定收件人:
/// @notice Deposit ETH to Layer 2 - transfer ether from user into contract, validate it, register deposit
/// @param _zkSyncAddress The receiver Layer 2 address
function depositETH(address _zkSyncAddress) external payable {
require(_zkSyncAddress != SPECIAL_ACCOUNT_ADDRESS, "P");
require(msg.value > 0, "M"); // Zero-value deposits are forbidden by zkSync rollup logic
requireActive();
registerDeposit(0, SafeCast.toUint128(msg.value), _zkSyncAddress);
}如果这正是我们想要达到的目标,我们如何传递一个ZkSync帐户地址?
如果您看一下一个例子,ZkSync团队为Swift提供了:
let ethereumProvider = try self.wallet.createEthereumProvider(web3: Web3.InfuraRinkebyWeb3())
firstly {
ethereumProvider.deposit(token: .ETH,
amount: amount,
userAddress: wallet.address) /// Ethereum wallet address is provided
}.done { (_) in
self.present(UIAlertController.for(message: "Successfully deposited"), animated: true, completion: nil)
}.catch { (error) in
self.present(UIAlertController.for(error: error), animated: true, completion: nil)
}定金的参数是发件人的地址,它是Ethereum网络上的帐户,而不是ZkSync。
func depositETH(address: EthereumAddress, value: BigUInt) -> Promise<TransactionSendingResult> {
guard let tx = self.contract.write("depositETH",
parameters: [address] as [AnyObject], // here the parameter passed for the depositETH method of the smart contract is the address of the sender's account, which is the Ethereum account.
transactionOptions: createOptions(value: value)) else {
return Promise(error: ZkSyncContractError.invalidParameters)
}
return tx.sendPromise()
}如果执行上述代码,将得到以下错误:

根据web3swift源代码,这个神秘的错误似乎表明了连接错误,因为它似乎表示错误1。
public enum Web3Error: Error {
case transactionSerializationError
case connectionError
case dataError
case walletError
case inputError(desc:String)
case nodeError(desc:String)
case processingError(desc:String)
case keystoreError(err:AbstractKeystoreError)
case generalError(err:Error)
case unknownError那么,要创建一个新的ZkSync帐户,您必须将什么地址传递给存款方法?Swift示例是否通过传递电子邮件帐户的发件人地址来正确?如果是,错误的根源是什么?
更新
Swift示例代码中存款过程的顺序如下所示:
guard let wallet = try? DefaultWallet<ChangePubKeyECDSA, DefaultEthSigner>(ethSigner: ethSigner,
zkSigner: zkSigner,
provider: provider) else {
fatalError()
}let ethereumProvider = try self.wallet.createEthereumProvider(web3: Web3.InfuraRinkebyWeb3())
firstly {
ethereumProvider.deposit(token: .ETH,
amount: amount,
userAddress: wallet.address)
}.done { (_) in
self.present(UIAlertController.for(message: "Successfully deposited"), animated: true, completion: nil)
}.catch { (error) in
self.present(UIAlertController.for(error: error), animated: true, completion: nil)
}但是,如果我的理解是正确的,存款方法中的userAddress参数应该是收件人的地址。然而,wallet.address是寄件人的地址。
public var address: String {
self.ethSigner.address
}在调用存款方法之前,我生成了一个新的Ethereum地址来发送资金,希望它能在Zksync中生成一个新帐户,但仍然得到了相同的错误。
KeysService().getWalletPrivateKey(password: password, completion: { [weak self] privateKey, error in
if let error = error {
print(error)
}
if let privateKey = privateKey {
do {
guard let newWallet = self?.createZKWallet(.rinkeby, privateKey: privateKey) else { return }
let ethereumProvider = try newWallet.createEthereumProvider(web3: Web3.InfuraRinkebyWeb3())
firstly {
ethereumProvider.deposit(token: .ETH,
amount: amount,
userAddress: newWallet.address)
}.done { (_) in
self?.present(UIAlertController.for(message: "Successfully deposited"), animated: true, completion: nil)
}.catch { (error) in
self?.present(UIAlertController.for(error: error), animated: true, completion: nil)
}
} catch {
self?.present(UIAlertController.for(error: error), animated: true, completion: nil)
}
}
})发布于 2022-04-26 12:38:46
您需要传递一个新地址(收件人地址)。无法按您的状态从“不存在”地址发送。
您可以通过从私钥随机生成地址来“创建”地址,或者在您已经知道地址的情况下复制它。
与您的问题相关,示例应用程序使用的帐户目前在Ethereum上没有任何资金(0x46a23e25df9a0f6c18729dda9ad1af3b6a131160) (见屏幕快照)。我寄了一小笔钱,现在可以用了。

发布于 2022-05-03 18:07:32
要创建一个zkSync帐户,我们需要以某种方式与我们的钱包交互: f.e.:我们可以从任何分散的钱包中存入L1→L2,这意味着帐户已经创建或者转移到现有地址l2→l2,这也是可行的。但要与这些基金合作,我们将需要激活我们的L2 -使CPK,支付一些费用。否则,我们将需要做替代退出。
https://stackoverflow.com/questions/71994734
复制相似问题