如何创建ZKSYNC帐户?

发布于 01-24 07:13 字数 5736 浏览 2 评论 0 原文

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帐户地址,如果我们要实现的目标?

If you take a look at

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)
}

存款的参数是发件人的地址,该地址是以太坊网络上的帐户,而不是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 SDK示例是否通过传递以太坊帐户的发件人地址正确?如果是这样,错误的来源是什么?

更新

Swift SDK示例代码中存款过程的顺序如下

  1. : /examples/cocoapods/zksyncexample/viewcontrollers/networkselectiontableviewcontroller.swift#l52“ rel =“ nofollow noreferrer”>钱包>钱包创建的
guard let wallet = try? DefaultWallet<ChangePubKeyECDSA, DefaultEthSigner>(ethSigner: ethSigner,
                                                                           zkSigner: zkSigner,
                                                                           provider: provider) else {
    fatalError()
}
  1. 钱包被传递给了沉积视图,并用于发送存款
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, however, is the

public var address: String {
    self.ethSigner.address
}

在调用存款方法之前,我生成了一个新的以太坊地址,以将资金发送给,希望它可以在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)
        }
    }
})

The ZkSync documentation states that a deposit has to be made from an existing Ethereum account to a non-existing ZkSync account counterfactually in order to create a new account.

However, the method that is used to make the deposit already takes a ZkSync account address as a parameter to specify the recipient:

/// @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);
}

How do we pass a ZkSync account address if that's the very thing we're trying to achieve?

If you take a look at one of examples the ZkSync team provided for the Swift SDK:

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)
}

The parameter for the deposit is the address of the sender which is the account on the Ethereum network, not ZkSync.

Source

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()
}

If you execute above code, you get the following error:

enter image description here

This mysterious error seems to indicate a connection error according to the web3swift source code, since it seems to say error 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

So what address do you have to pass to the deposit method in order to create a new ZkSync account? Is the Swift SDK example correct by passing a sender's address of an Ethereum account? If so, what is the source of the error?

Update

The sequence of the deposit process in the Swift SDK's example code goes something like following:

  1. A wallet is created
guard let wallet = try? DefaultWallet<ChangePubKeyECDSA, DefaultEthSigner>(ethSigner: ethSigner,
                                                                           zkSigner: zkSigner,
                                                                           provider: provider) else {
    fatalError()
}
  1. The wallet is passed to a depositing view controller and is used to send a deposit.
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)
}

But, if my understanding if correct, the userAddress parameter in the deposit method is supposed to be the recipient's address. wallet.address, however, is the address of the sender.

public var address: String {
    self.ethSigner.address
}

Prior to calling the deposit method, I generated a new Ethereum address to send the funds to in hopes that it could generate a new account in Zksync, but still got the same error.

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)
        }
    }
})

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

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

发布评论

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

评论(2

紧拥背影 2025-01-31 07:13:25

您需要传递新地址(收件人地址)。当您说明时,无法从“不存在”地址发送。

您可以通过从私钥随机生成地址来“创建”该地址,或者如果已经知道地址,则可以复制它。

与您的问题相关的示例应用程序使用一个帐户,该帐户当前在以太坊上(0x46A23E25DF9A0F6C18729DDA9AD1AF3B6A131160)(请参阅ScreenShot)。我发送了少量,现在可以工作。

You need to pass a new address (recipient address). Can't send from a 'non-existing' address as you state.

You can 'create' the address by generating it randomly from a private key, or by copying it if you know the address already.

Related to your problem, the example app uses an account that currently doesn't have any funds on Ethereum (0x46a23e25df9a0f6c18729dda9ad1af3b6a131160) (see screenshot). I've sent a small amount and it will work now.

enter image description here

猫九 2025-01-31 07:13:25

要创建一个zksync帐户,我们需要以某种方式与钱包互动:fe:我们可以从任何去中心化的钱包L1→l2中存入存款,这意味着创建帐户或转移到现有地址L2→L2,它将也可以可行。但是要使用这笔资金,我们需要激活我们的L2-制作CPK,支付一些费用。否则,我们需要进行替代撤回。

to create a zkSync account we need to interact with our wallet somehow: f.e.: We can make a deposit from any decentralized wallet L1→L2 and it will mean that account was created or make a transfer to the existing address l2→l2 and it will be also workable. But to work with this funds we will need activate our L2 - make CPK, pay some fee. Otherwise we will need to do alternative withdraw.

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