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

Cannot convert value of type 'Promise<EthereumQuantity>' to closure result type 'Guarantee<T>' #92

Open
simibac opened this issue Dec 5, 2020 · 2 comments

Comments

@simibac
Copy link

simibac commented Dec 5, 2020

Running the code snippet from the README for sending an ETH tx fails:

let privateKey = try! EthereumPrivateKey(hexPrivateKey: "0xa26da69ed1df3ba4bb2a231d506b711eace012f1bd2571dfbfff9650b03375af")
firstly {
    web3.eth.getTransactionCount(address: privateKey.address, block: .latest)
}.then { nonce in
    let tx = try EthereumTransaction(
        nonce: nonce,
        gasPrice: EthereumQuantity(quantity: 21.gwei),
        gas: 21000,
        to: EthereumAddress(hex: "0xC0866A1a0ed41e1aa75c932cA3c55fad847fd90D", eip55: true),
        value: EthereumQuantity(quantity: 1.eth)
    )
    return try tx.sign(with: privateKey, chainId: 1).promise
}.then { tx in
    web3.eth.sendRawTransaction(transaction: tx)
}.done { hash in
    print(hash)
}.catch { error in
    print(error)
}

Error for web3.eth.getTransactionCount(address: privateKey.address, block: .latest):

Cannot convert value of type 'Promise' to closure result type 'Guarantee'

and for }.then { nonce in:

Invalid conversion from throwing function of type '(_) throws -> Guarantee' to non-throwing function type '(T) -> Guarantee'

I am using Xcode 12.2, Web3 (0.5.3), PromiseKit(6.13.3)

@JulianKakarott
Copy link

JulianKakarott commented Dec 27, 2020

Replace both .then with .map and delete .promise at the return statement.

@shuvayansaha
Copy link

shuvayansaha commented Aug 14, 2021

This piece of code is working.

firstly {
    web3.eth.getTransactionCount(address: privateKey.address, block: .latest)
}.then { nonce -> Promise<EthereumSignedTransaction> in
    let tx = try EthereumTransaction(
        nonce: nonce,
        gasPrice: EthereumQuantity(quantity: 21.gwei),
        gas: 21000,
        to: EthereumAddress(hex: toAddress, eip55: true),
        value: EthereumQuantity(quantity: BigUInt(10000000000000000))
    )
    return try tx.sign(with: privateKey, chainId: 3).promise
}.then { tx in
    web3.eth.sendRawTransaction(transaction: tx)
}.done { hash in
    print(hash.hex())
}.catch { error in
    print(error)
}

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