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 #283

Closed
DarcyLau opened this issue Oct 16, 2020 · 4 comments
Closed

Failed to fetch gas estimate #283

DarcyLau opened this issue Oct 16, 2020 · 4 comments

Comments

@DarcyLau
Copy link

DarcyLau commented Oct 16, 2020

When I call a contract method and get this error,
`let url = URL(string: nodeAddress)
let web3 = try Web3.new(url!)
web3.provider.network = Networks.Custom(networkID: BigUInt("666666"))
web3.addKeystoreManager(self.keystoreManager!)

            let walletAddress = EthereumAddress(fromAddress)! // Your wallet address
            let contractMethod = "addRig" // Contract method you want to call

            let filePath = Bundle.main.path(forResource: "pledge4thor", ofType: "abi")!
            let contractABI = try String(contentsOfFile: filePath) // Contract ABI

            let contractAddress = EthereumAddress(contractAddressStr)!
            let abiVersion = 2 // Contract ABI version
            let contract = web3.contract(contractABI, at: contractAddress, abiVersion: abiVersion)!
            var options = TransactionOptions.defaultOptions
            options.from = walletAddress
            options.gasPrice = .automatic
            options.gasLimit = .automatic
            options.value = Web3.Utils.parseToBigUInt("99", units: .eth)
    
            let parameters = [rigStr as AnyObject]
            
            let tx = contract.method(contractMethod, parameters: parameters, extraData: Data(), transactionOptions: options)
            tx?.transaction.nonce = try (web3.eth.getTransactionCount(address: walletAddress))
    
            let result = try tx?.send(password: "q12345678", transactionOptions: options)`

and this is my func in abi:
{
"inputs": [
{
"internalType": "bytes32",
"name": "rig",
"type": "bytes32"
}
],
"name": "addRig",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}

so I'v seen this error before, that time I deleted the line to set options.value and put amount in parameters, this time when I tried like this, the transaction returned nil

@DarcyLau
Copy link
Author

So I tried to send a rig which length is 32, it works fine, but the rig I got is a 66 length string, how should I do

@dangell7
Copy link

This is an issue with your parameters typically.

Transfer Example:

let parameters = [
    ethBeneficiary as Any,
    weiValue as Any,
] as [AnyObject]
let transaction = contract.write(
    "transfer",
    parameters: parameters as [AnyObject],
    extraData: Data(),
    transactionOptions: options
)

@dangell7
Copy link

Another reason is because the contract is rejecting the transaction.

For instance, I just got the same error because the user submitting the transaction was not an owner on the contract.

Not sure if this is EXACTLY correct, but I added the user as an owner, and then the transaction went through.

@Iysbaera
Copy link
Collaborator

@DarcyLau Hey, did you find a solution for this issue?

@Iysbaera Iysbaera closed this as completed Nov 5, 2021
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

3 participants