Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to fetch gas estimate #178

Closed
SteadyAction opened this issue Apr 30, 2019 · 1 comment
Closed

Failed to fetch gas estimate #178

SteadyAction opened this issue Apr 30, 2019 · 1 comment

Comments

@SteadyAction
Copy link

SteadyAction commented Apr 30, 2019

I get this message Failed to fetch gas estimate for try tx.send(password: password)

public func sendTokenSync(to toAddress: String, contractAddress: String, amount: String, password: String, gasPrice:
        String?) throws -> String {
        if access == .viewOnly { throw WalletError.notAllowedAccess }
        
        guard let myAddress = address,
            let myEthereumAddress = EthereumAddress(myAddress),
            let toEthereumAddress = EthereumAddress(toAddress),
            let erc20ContractAddress = EthereumAddress(contractAddress),
            let contract = web3Instance.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2) else {
                throw WalletError.invalidAddress
        }
        
        guard let decimals = try? decimalsForToken(contractAddress: contractAddress) else {
            throw WalletError.unexpectedResult
        }
        
        var options = TransactionOptions.defaultOptions
        options.value = Web3.Utils.parseToBigUInt(amount, decimals: decimals)
        options.from = myEthereumAddress
        
        if let gasPrice = gasPrice,
            let wei = Web3.Utils.parseToBigUInt(gasPrice, units: .eth) {
            options.gasLimit = .manual(defaultGasLimitForTokenTransfer)
            options.gasPrice = .manual(wei)
        }
        
        guard let tx = contract.write("transfer", parameters: [toEthereumAddress, options.value] as [AnyObject], extraData: Data(), transactionOptions: options) else {
            throw WalletError.unexpectedResult
        }
        
        let txResult = try tx.send(password: password)
        return txResult.hash
    }

same for automatic gasLimit and gasPrice

@SteadyAction
Copy link
Author

SteadyAction commented Apr 30, 2019

SOLVED. It works after I remove options.value = ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant