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

Error: Failed to fetch gas estimate on intermediate call #106

Closed
barrasso opened this issue Dec 11, 2018 · 1 comment
Closed

Error: Failed to fetch gas estimate on intermediate call #106

barrasso opened this issue Dec 11, 2018 · 1 comment

Comments

@barrasso
Copy link
Contributor

Hi All, I am having some trouble calling a method on the ENS registrar contract. Some methods work fine, while others give me a gas estimation error.

For example, I am able to call startAuction with no problems like so:

let parameters = ["0x\(name.labelHash!)"] as [AnyObject]
DispatchQueue.global().async {
    let gasPriceResult = Keys.shared.web3.eth.getGasPrice()
    guard case .success(let gasPrice) = gasPriceResult else {return}
    var options = Web3Options.defaultOptions()
    options.gasPrice = gasPrice
    options.gasLimit = BigUInt(200000)
    options.from = Keys.shared.manager?.addresses?.first!
    DispatchQueue.global().async {
        let contract = Keys.shared.web3.contract(Web3.Utils.registrarABI, at: ENSRegistrar.registrarContract, abiVersion: 2)!
        let intermediate = contract.method("startAuction", parameters: parameters, options: options)
        guard let res = intermediate?.send(password: "PASSWORD") else {return}
        switch res {
        case .success(let res):
            completion(true, nil)
        case .failure(let error):
            completion(false, error)
        }
    }
}

Starting the auction works fine and the tx goes through: https://ropsten.etherscan.io/tx/0x59ad6cfa53985301ecdf6c07df20b02e55aa31965a45e14e0b2f6b3ec5e85823

However, when I try to call newBid in the same manner, I get a gas estimation error.

This is the error I am getting. It happens at the case .failure line:

failure res: .failure(processingError(desc: "Failed to fetch gas estimate"))

Here is my code calling newBid:

let parameters = ["0x\(sealedBid!)"] as [AnyObject]
DispatchQueue.global().async {
    let gasPriceResult = Keys.shared.web3.eth.getGasPrice()
    guard case .success(let gasPrice) = gasPriceResult else {return}
    var options = Web3Options.defaultOptions()
    options.gasPrice = gasPrice
    options.gasLimit = BigUInt(200000)
    options.from = Keys.shared.manager?.addresses?.first!
    let contract = Keys.shared.web3.contract(Web3.Utils.registrarABI, at: ENSRegistrar.registrarContract, abiVersion: 2)!
    let intermediate = contract.method("newBid", parameters: parameters, options: options)
    DispatchQueue.global().async {
        guard let res = intermediate?.send(password: "PASSWORD") else {return}
        switch res {
        case .success(_):
            completion(true, nil)
        case .failure(let error):
            // this is where I'm getting a gas estimation error
            print("failure res: \(res)")
            completion(false, error)
        }
}

I am using the following contract on Ropsten: https://ropsten.etherscan.io/address/0xc19fd9004b5c9789391679de6d766b981db94610#code

And here's the ABI:

public static var registrarABI = """
    [{"constant":false,"inputs":[{"name":"_hash","type":"bytes32"}],"name":"releaseDeed","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_hash","type":"bytes32"}],"name":"getAllowedTime","outputs":[{"name":"timestamp","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"unhashedName","type":"string"}],"name":"invalidateName","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"hash","type":"bytes32"},{"name":"owner","type":"address"},{"name":"value","type":"uint256"},{"name":"salt","type":"bytes32"}],"name":"shaBid","outputs":[{"name":"sealedBid","type":"bytes32"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"bidder","type":"address"},{"name":"seal","type":"bytes32"}],"name":"cancelBid","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_hash","type":"bytes32"}],"name":"entries","outputs":[{"name":"","type":"uint8"},{"name":"","type":"address"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"ens","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_hash","type":"bytes32"},{"name":"_value","type":"uint256"},{"name":"_salt","type":"bytes32"}],"name":"unsealBid","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_hash","type":"bytes32"}],"name":"transferRegistrars","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"bytes32"}],"name":"sealedBids","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_hash","type":"bytes32"}],"name":"state","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_hash","type":"bytes32"},{"name":"newOwner","type":"address"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_hash","type":"bytes32"},{"name":"_timestamp","type":"uint256"}],"name":"isAllowed","outputs":[{"name":"allowed","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_hash","type":"bytes32"}],"name":"finalizeAuction","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"registryStarted","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"sealedBid","type":"bytes32"}],"name":"newBid","outputs":[],"payable":true,"type":"function"},{"constant":false,"inputs":[{"name":"labels","type":"bytes32[]"}],"name":"eraseNode","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_hashes","type":"bytes32[]"}],"name":"startAuctions","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"hash","type":"bytes32"},{"name":"deed","type":"address"},{"name":"registrationDate","type":"uint256"}],"name":"acceptRegistrarTransfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_hash","type":"bytes32"}],"name":"startAuction","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"rootNode","outputs":[{"name":"","type":"bytes32"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"hashes","type":"bytes32[]"},{"name":"sealedBid","type":"bytes32"}],"name":"startAuctionsAndBid","outputs":[],"payable":true,"type":"function"},{"inputs":[{"name":"_ens","type":"address"},{"name":"_rootNode","type":"bytes32"},{"name":"_startDate","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"hash","type":"bytes32"},{"indexed":false,"name":"registrationDate","type":"uint256"}],"name":"AuctionStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"hash","type":"bytes32"},{"indexed":true,"name":"bidder","type":"address"},{"indexed":false,"name":"deposit","type":"uint256"}],"name":"NewBid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"hash","type":"bytes32"},{"indexed":true,"name":"owner","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"status","type":"uint8"}],"name":"BidRevealed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"hash","type":"bytes32"},{"indexed":true,"name":"owner","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"registrationDate","type":"uint256"}],"name":"HashRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"hash","type":"bytes32"},{"indexed":false,"name":"value","type":"uint256"}],"name":"HashReleased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"hash","type":"bytes32"},{"indexed":true,"name":"name","type":"string"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"registrationDate","type":"uint256"}],"name":"HashInvalidated","type":"event"}]
    """

I'm not sure why one function is working while the other is throwing gas estimation errors. Is there a way to NOT use the gas estimator? Thanks!

@barrasso
Copy link
Contributor Author

Found the error.

Must set options.value = BID_VALUE+MASKED_VALUE, when calling the newBid function.

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