如何创建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帐户地址,如果我们要实现的目标?
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示例代码中存款过程的顺序如下
- : /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()
}
- 钱包被传递给了沉积视图,并用于发送存款。
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)
}
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要传递新地址(收件人地址)。当您说明时,无法从“不存在”地址发送。
您可以通过从私钥随机生成地址来“创建”该地址,或者如果已经知道地址,则可以复制它。
与您的问题相关的示例应用程序使用一个帐户,该帐户当前在
以太坊上
(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.要创建一个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.