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

gas required exceeds allowance or always failing transaction #860

Open
sonukumar35 opened this issue Jun 6, 2024 · 1 comment
Open

gas required exceeds allowance or always failing transaction #860

sonukumar35 opened this issue Jun 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@sonukumar35
Copy link

What happened?

I am trying to send vote using ABI string and contract address, but getting error message always , i have tried changing options, args , parameters several time but getting same response

What are the steps to reproduce?

func voteSmartContract(voteCount: Double) {

    guard let urlStr = URL(string: rpcURL) else {
        print(" error in creating URL die rpc \(#file)  ===> \(#function)")
        return
    }

    guard let kManager = wethioKeystoreManager else { return }

    web3ProvideInstance = Web3HttpProvider(urlStr, keystoreManager: kManager)
    guard let wProvier = self.web3ProvideInstance else {return}

    self.web3Instance = Web3(provider: wProvier)
    guard let wInstance = self.web3Instance else {return}

    DispatchQueue.global(qos: .background).async {
        do {

            let validatorContractEthAddress = EthereumAddress(self.contractAddress)

            let toaddress = EthereumAddress(self.candidateMasternode!.candidate!)

            let senderEthAddress = EthereumAddress(self.etheriumAccountAddress ?? "")

            let estimateGasPrice = try wInstance.eth.getGasPrice()
            print(estimateGasPrice)

            let amountDouble = BigInt((voteCount)*pow(10, 18))

            let amount = BigUInt.init(amountDouble)


            var options = Web3Options.defaultOptions()

            options.from = senderEthAddress
            options.gasLimit = 37162 //gas estimated price
            options.value = amount
            options.gasPrice = 250000000

            let tokenTransactionIntermediate = try wInstance.contract(Web3.Utils.validatorABI2, at: validatorContractEthAddress).method("vote", args: toaddress, options: options)

            let mainTransaction = try? tokenTransactionIntermediate.send(options: options, onBlock: "latest")

            print(mainTransaction)
            print(mainTransaction?.hash)

            DispatchQueue.main.async {
                self.loaderInstance.hideIndicator()

            }

        } catch {
            print(error)
            DispatchQueue.main.async {
                self.loaderInstance.hideIndicator()
                self.showAlertMessage(message: "Unable to send Token")
            }
        }
    }
}

What is the expected behavior?

I expect that this function should return a valid hash after completing smart contract to the vote function

What is the error thrown?

web3swift.JsonRpcResponse.ErrorMessage(code: -32000, message: "gas required exceeds allowance or always failing transaction")

What's the stack trace said?

func voteSmartContract(voteCount: Double) {

    guard let urlStr = URL(string: rpcURL) else {
        print(" error in creating URL die rpc \(#file)  ===> \(#function)")
        return
    }

    guard let kManager = wethioKeystoreManager else { return }

    web3ProvideInstance = Web3HttpProvider(urlStr, keystoreManager: kManager)
    guard let wProvier = self.web3ProvideInstance else {return}

    self.web3Instance = Web3(provider: wProvier)
    guard let wInstance = self.web3Instance else {return}

    DispatchQueue.global(qos: .background).async {
        do {

            let validatorContractEthAddress = EthereumAddress(self.contractAddress)

            let toaddress = EthereumAddress(self.candidateMasternode!.candidate!)

            let senderEthAddress = EthereumAddress(self.etheriumAccountAddress ?? "")

            let estimateGasPrice = try wInstance.eth.getGasPrice()
            print(estimateGasPrice)

            let amountDouble = BigInt((voteCount)*pow(10, 18))

            let amount = BigUInt.init(amountDouble)


            var options = Web3Options.defaultOptions()

            options.from = senderEthAddress
            options.gasLimit = 37162 //gas estimated price
            options.value = amount
            options.gasPrice = 250000000

            let tokenTransactionIntermediate = try wInstance.contract(Web3.Utils.validatorABI2, at: validatorContractEthAddress).method("vote", args: toaddress, options: options)

            let mainTransaction = try? tokenTransactionIntermediate.send(options: options, onBlock: "latest")

            print(mainTransaction)
            print(mainTransaction?.hash)

            DispatchQueue.main.async {
                self.loaderInstance.hideIndicator()

            }

        } catch {
            print(error)
            DispatchQueue.main.async {
                self.loaderInstance.hideIndicator()
                self.showAlertMessage(message: "Unable to send Token")
            }
        }
    }
}

OS version

mac OS 12.6.2

Library version

web3swift.pod (2.1.10)
xcode Version 14.1

@sonukumar35 sonukumar35 added the bug Something isn't working label Jun 6, 2024
@WazirxDax
Copy link

@sonukumar35 Have you found the solution? I am facing same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants