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

web3swift.Web3Error.processingError("Failed to fetch nonce") #272

Closed
DarcyLau opened this issue Aug 19, 2020 · 4 comments
Closed

web3swift.Web3Error.processingError("Failed to fetch nonce") #272

DarcyLau opened this issue Aug 19, 2020 · 4 comments

Comments

@DarcyLau
Copy link

DarcyLau commented Aug 19, 2020

When I try to transfer token to another account, why is it always this error
web3swift.Web3Error.processingError("Failed to fetch nonce")

let url = URL.init(string: nodeAddress)
            let web3 = Web3(url: url!)
            let walletAddress = EthereumAddress(fromAddress) // Your wallet address
            let toAddress = EthereumAddress(toAddress)
            let erc20ContractAddress = EthereumAddress(contractAddress)
            let amount = Web3.Utils.parseToBigUInt(amount, units: .eth)
            var options = Web3Options.defaultOptions()
            options.value = amount
            options.from = walletAddress
            options.to = toAddress
            options.gasLimit = try web3?.eth.getBlockNumber()
            options.gasPrice = try web3?.eth.getGasPrice()
            let method = "transfer"
            guard let tokenContract = try web3?.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress) else {
                print("error no created token address")
                return
            }
            let parameters = [toAddress as AnyObject, amount as Any] as [AnyObject]
            let transactionContract = try tokenContract.method(method, parameters: parameters, options: options)
            transactionContract.transaction.nonce = try (web3?.eth.getTransactionCount(address: Address(fromAddress)))!
            let results = try transactionContract.send(password: pass, options: options, onBlock: "")
@skywinder
Copy link
Collaborator

Hello. Looks like you didn't send transaction before fetching nonce. Try to switch last 2 strings in your example.

@skywinder
Copy link
Collaborator

Feel free to reopen the issue, if you still need help. 👍

@ayjayem
Copy link

ayjayem commented Oct 19, 2020

Hi there,

This seems like a great library - thanks so much for providing!

I am also facing this error: 'Fatal error: 'try!' expression unexpectedly raised an error: Web3swift.Web3Error.processingError(desc: "Failed to fetch nonce").'

I'm sure I'm just doing something silly - any assistance would be very much appreciated:

    let web3 = Web3.InfuraMainnetWeb3()
    let walletAddress = EthereumAddress(wallet!.address!)!

    let contractMethod = "approve"
    let DAIcontractAddress = EthereumAddress(daiAddressString)!
    let abiVersion = 2
    
    let approvalUnits = "1000"
    let approveAmount = Web3.Utils.parseToBigUInt(approvalUnits, units: .wei)!
    
    let approveAddress = EthereumAddress(erc20AddressString)!
    
    let parameters: [AnyObject] = [approveAddress as AnyObject, approveAmount as AnyObject] as [AnyObject]
    let extraData: Data = Data()
    let contract = web3.contract(Web3.Utils.erc20ABI, at: DAIcontractAddress, abiVersion: abiVersion)!
    var options = TransactionOptions.defaultOptions
    options.from = walletAddress
    options.gasPrice = .automatic
    options.gasLimit = .automatic
    let tx = contract.write(
        contractMethod,
        parameters: parameters,
        extraData: extraData,
        transactionOptions: options)!
    
    _ = try! tx.send(password: password)

@skywinder
Copy link
Collaborator

@alexandermucalov, sometimes it happens with infura issues. Ping me in the telegram, we can debug it, and I can provide you more support with this!

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

No branches or pull requests

3 participants