Boilertalk / Web3.swift

A pure swift Ethereum Web3 library
MIT License
639 stars 188 forks source link

Question about balances #96

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hey guys,

Great job with the library - just having fun and tinkering around and wanted to ask a question about the return value EthereumQuantity

If I make a request for a balance like so:

private func getMyEthereumBalance() {
        do {
            let myAddress = try EthereumAddress(hex: "some_hex", eip55: false)
            firstly {
                web3.eth.getBalance(address: myAddress, block: .latest)
            }.done { eth in
                print(eth.quantity)
            }.catch { error in
                print("Error")
            }
        } catch {
            print(error.localizedDescription)
        }
    }

the eth.quantity comes back as a BigUInt... Question is: what in the world does this int represent lol? I am assuming it's an integer based representation of the value at that address but how would one go about converting it to like the amount of ether as a fraction? like 1.233 instead of the large integer?

ghost commented 3 years ago

Nvm got it -> wei converter 👍 thanks guys hope you keep the project alive.