Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Send ERC-20 Token error #251

Closed
CYC666 opened this issue Mar 27, 2020 · 5 comments
Closed

Send ERC-20 Token error #251

CYC666 opened this issue Mar 27, 2020 · 5 comments
Labels
question Further information is requested wontfix This will not be worked on

Comments

@CYC666
Copy link

CYC666 commented Mar 27, 2020

// 交易
let value: String = amountStr
let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
let toAddress = EthereumAddress(toAddressStr)!
let erc20ContractAddress = EthereumAddress("0xaB8Ad2d7f39A54960Be8b71e01276a9E897833eE", ignoreChecksum:true)!
let contract = self.web3.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2)!
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
var options = TransactionOptions.defaultOptions
options.value = amount
options.from = walletAddress
options.gasPrice = .automatic
options.gasLimit = .automatic
let method = "transfer"
let tx = contract.write(
method,
parameters: [toAddress, amount] as [AnyObject],
extraData: Data(),
transactionOptions: options)!

            let res = try tx.send(password: password, transactionOptions: options)
            print(res.hash)

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

@suusofttruongnv
Copy link

I also get an error when I try to send the token to a different address

    let web3 = getWeb3()
    let walletAddress = EthereumAddress(wallet_token.address)! // Your wallet address
    let toAddress = EthereumAddress(toAddressString)!
    let erc20ContractAddress = EthereumAddress(token.address)!
    let contract = web3.contract( Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2)! 
    let amount = Web3.Utils.parseToBigUInt(value, decimals: token.decimals)
    var options = TransactionOptions.defaultOptions
    options.value = amount
    options.from = walletAddress
    options.gasPrice = .automatic
    options.gasLimit = .automatic
    let method = "transfer"
    let tx = contract.write(
        method,
        parameters: [toAddress, amount] as [AnyObject],
        extraData: Data(),
        transactionOptions: options)!
    
    do {
        let result = try tx.send(password: "web3swift")
        print("\(TAG) result")
        return result
    } catch let error {
        print("\(TAG) error" + error.localizedDescription)
        throw error
    }

It appears an error like this:

PromiseKit: warning: wait() called on main thread!
error The operation couldn’t be completed. (web3swift.Web3Error error 2.)

Please help me, what do I have to do to fix it, and send my ERC token smoothly?

Thanks!

@CYC666
Copy link
Author

CYC666 commented Apr 7, 2020

change:

options.value = Web3.Utils.parseToBigUInt("0", decimals: token.decimals)

no thanks.

@suusofttruongnv
Copy link

Thank you very much!!!

@CYC666
Copy link
Author

CYC666 commented Apr 7, 2020

Thank you very much!!!
cyc1154490751
this is my WeChat id

@skywinder
Copy link
Collaborator

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

@skywinder skywinder added question Further information is requested wontfix This will not be worked on labels Sep 23, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants