You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By changing the method in following code we can fetch the balance , decimal , symbol and name of ERC20Token. Is there any way to fetch all at once instead of changing method all the time?
if let address = tokenAddress,
let walletAddress = self.publicAddress {
let exploredAddress = EthereumAddress(walletAddress)
let erc20TokenAddress = EthereumAddress(address)
guard let tokenContract = web3?.contract(Web3.Utils.erc20ABI, at: erc20TokenAddress, abiVersion: 2) else {
print("error no created token address")
return
}
var options = Web3Options.defaultOptions()
options.from = EthereumAddress(walletAddress)
let method = "balanceOf"
let transactionContract = tokenContract.method(method, parameters: [exploredAddress] as [AnyObject], options: options)
DispatchQueue.main.async {
let results = transactionContract?.call(options: options)
switch results! {
case .success(let response):
#warning("decimals fetch from contract!")
let tokenBalance = "\(response.map({$0}).first?.value)"
let actualTknBalance = CGFloat(BigUInt(tokenBalance)! / BigUInt(10000000))
completion("\(actualTknBalance)")
case .failure(let failure):
print(failure.localizedDescription)
}
}
}
The text was updated successfully, but these errors were encountered:
HI @BaldyAsh
I user this to get ERC20 balance
let balance = token.getBalance(account: )
in bsc chain It worked
but in gate.io RPC: https://evm.gatenode.cc node: 86, it throw in web3.Eth class callPromise method.
web3swift.Web3Error.nodeError(desc: "{"codespace":"framework","code":1,"message":"gas price cannot be 0"}")
I user method 'Get ERC20 token balance' example it error too
Can you help me how to solve the problem?
By changing the method in following code we can fetch the balance , decimal , symbol and name of ERC20Token. Is there any way to fetch all at once instead of changing method all the time?
The text was updated successfully, but these errors were encountered: