EtherWallet is an iOS toolbelt for interaction with the Ethereum network.
For more specific usage, please refer to the demo
Add this to your podfile and run pod install
to install:
pod 'web3swift-alpha', '~> 1.1.1'
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding EtherWallet as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.package(url: "https://github.com/smithSophiav/EtherWallet.git", .upToNextMajor(from: "1.1.1"))
]
import web3swift_alpha
import EtherWallet
let web3 = Web3_v1()
if web3.isWeb3LoadFinished {
} else {
web3.setup { [weak self] web3LoadFinished in
guard let self = self else { return }
if web3LoadFinished {}
}
}
web3.generateAccount(password: password) { [weak self] (state, address,mnemonic,privateKey, keystore,error) in
guard let self = self else { return }
self.generateAccountBtn.isEnabled = true
if state {
let text =
"address: " + address + "\n\n" +
"mnemonic: " + mnemonic + "\n\n" +
"privateKey: " + privateKey + "\n\n" +
"keystore: " + keystore
generateAccountTextView.text = text
} else {
generateAccountTextView.text = error
}
}
web3.importAccount(mnemonic: mnemonic, encrypedPassword: encrypedPassword){ [weak self] (state,address,privateKey,keystore,error) in
guard let self = self else { return }
self.importAccountBtn.isEnabled = true
if state {
let text =
"address: " + address + "\n\n" +
"privateKey: " + privateKey + "\n\n" +
"keystore: " + "\n" + keystore
self.importAccountTextView.text = text
} else {
self.importAccountTextView.text = error
}
}
web3.importAccount(decryptPassword: password, keystore: Keystore) { [weak self] (state, address, privateKey,error) in
guard let self = self else { return }
self.importAccountBtn.isEnabled = true
if state {
let text =
"address: " + address + "\n\n" +
"privateKey: " + privateKey
self.importAccountTextView.text = text
} else {
self.importAccountTextView.text = error
}
}
web3.importAccount(privateKey: privateKey, encrypedPassword: password){ [weak self] state, address, keystore,error in
guard let self = self else { return }
self.importAccountBtn.isEnabled = true
if state {
let text =
"address: " + address + "\n\n" +
"keystore: " + "\n" + keystore
self.importAccountTextView.text = text
} else {
self.importAccountTextView.text = error
}
}
let providerUrl = chainType == .main ? MainNet : "https://sepolia.infura.io/v3/fe816c09404d406f8f47af0b78413806"
web3.estimateETHTransactionFee(recipientAddress: reviceAddress,
senderAddress: senderAddress,
amount: amountText,
providerUrl: providerUrl) { [weak self] (state,estimateTransactionFee,gasEstimate,gasPrice,error) in
guard let self = self else { return }
print("state = \(state)")
print("estimateTransactionFee = \(estimateTransactionFee)")
if state {
self.hashLabel.text = "estimate Transaction Fee " + estimateTransactionFee + " ETH"
} else {
self.hashLabel.text = error
}
}
web3.ETHTransfer(recipientAddress: reviceAddress,
amount: amountText,
senderPrivateKey: privateKey,
providerUrl: providerUrl) { [weak self] (state,txid,error) in
guard let self = self else { return }
print("state = \(state)")
print("txid = \(txid)")
if state {
self.hashLabel.text = txid
} else {
self.hashLabel.text = error
}
}
web3.estimateERC20TransactionFee(providerUrl: providerUrl,
recipientAddress: reviceAddress,
senderAddress: senderAddress,
amount: amountText,
decimal: 6.0,
contractAddress: contractAddress) { [weak self] (state,estimateTransactionFee,gasEstimate,gasPrice,error) in
guard let self = self else { return }
print("state = \(state)")
print("estimateTransactionFee = \(estimateTransactionFee)")
if state {
self.hashLabel.text = "estimate Transaction Fee " + estimateTransactionFee + " ETH"
} else {
self.hashLabel.text = error
}
}
web3.erc20TokenTransfer(providerUrl: providerUrl,
senderPrivateKey: privateKey,
recipientAddress: reviceAddress,
erc20ContractAddress: contractAddress,
amount: amountText,
decimal: 6.0) { [weak self] (state,txid,error) in
guard let self = self else { return }
print("state = \(state)")
print("txid = \(txid)")
if state {
self.hashLabel.text = txid
} else {
self.hashLabel.text = error
}
}
For more detailed usage methods, it is recommended to refer to demo
EtherWallet is released under the MIT license. See LICENSE for details.