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(desc: "Failed to fetch gas estimate")(BSC Chain) #317

Closed
ciyaer opened this issue Apr 13, 2021 · 6 comments
Labels

Comments

@ciyaer
Copy link

ciyaer commented Apr 13, 2021

Error:
processingError(desc: "Failed to fetch gas estimate")

My code:

func sendBEP20Token() {
        let password = "web3swift"
        let privateKey = "XXX"
        let formattedKey = privateKey.trimmingCharacters(in: .whitespacesAndNewlines)
        let dataKey = Data.fromHex(formattedKey)!
        let keystore = try! EthereumKeystoreV3(privateKey: dataKey, password: password)
        let keystoreManager = KeystoreManager([keystore! as EthereumKeystoreV3])
        print(keystoreManager.addresses!)
        
        let endpoint = "https://data-seed-prebsc-1-s1.binance.org:8545/"
        let web333 = web3(provider: Web3HttpProvider(URL(string: endpoint)!, network: Networks.Custom(networkID: BigUInt(97)))!)
        web333.addKeystoreManager(keystoreManager)
        
        let value = "0.0001" // BTCB
        let decimal = 18
        //let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
        let amount = Web3.Utils.parseToBigUInt(value, decimals: decimal)!
        let address = EthereumAddress("0x9b16e5c921b6b82a36e101717708b3da411746a4")
        let toAddress = EthereumAddress("0x50bc2c973adf4b0071ac85c23beb646e5288c1b5")
        let tokenAddress = EthereumAddress("0x6ce8da28e2f864420840cf74474eff5fd80e65b8") // BTCB
        
        let contract = web333.contract(Web3.Utils.erc20ABI, at: tokenAddress, abiVersion: 2)!
        var options = TransactionOptions.defaultOptions
        options.value = amount
        options.from = address
        options.gasLimit = .automatic
        options.gasPrice = .automatic
        let tx = contract.write("transfer", parameters: [toAddress!, amount] as [AnyObject], extraData: Data(), transactionOptions: options)!
        
        do {
            let result = try tx.send(password: password)
            print(result)
            print(result.hash)
        } catch {
            print(error)
        }
    }

BSC Testnet Network:
https://testnet.bscscan.com/address/0x9b16e5c921b6b82a36e101717708b3da411746a4

BTCB Token:
https://testnet.bscscan.com/token/0x6ce8da28e2f864420840cf74474eff5fd80e65b8?a=0x9b16e5c921b6b82a36e101717708b3da411746a4

JSON-RPC Endpoint:
https://docs.binance.org/smart-chain/developer/rpc.html

ChainID (EVM Networks):
https://chainid.network

Binance Smart Chain Faucet:
https://testnet.binance.org/faucet-smart

@skywinder

@losedMemory
Copy link

Hi, Is this problem solved now?

@ciyaer
Copy link
Author

ciyaer commented Apr 23, 2021

Hi, Is this problem solved now?

😂NO,waiting for someone to help me

@skywinder
Copy link
Collaborator

Hi. Can't research it for now. Looks like it's some different parameters on the BSC side.

It would be nice to support BSC on a generalized level.
I'm ready to create a GitCoin bounty for someone, who is ready to implement it. (payment could be negotiable, depends on the amount of work) 👍

@skywinder skywinder added the BSC label May 10, 2021
@khimchuk00
Copy link

Just delete options.value = amount and it will work

@Iysbaera
Copy link
Collaborator

@khimchuk00 Hey, thank you for the advice.

@ciyaer Is this still and issue for your in the latest develop build or it was resolved?

@Iysbaera
Copy link
Collaborator

Iysbaera commented Nov 5, 2021

Authour of this issue haven't replied, so I suppose it was resolved and thus closing this issue.

To anyone still experiencing similar problems, feel free to reopen it.

@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
Projects
None yet
Development

No branches or pull requests

5 participants