Skip to content

Failed to fetch gas estimate #178

@SteadyAction

Description

@SteadyAction

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions