question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending transaction is not working

See original GitHub issue

When I try to send a transaction, it throws an error.

This is how I’m trying to sign and send it.

 func signTransaction() {
        let web3 = Web3.InfuraMainnetWeb3()
        let value: String = amountTextField.text ?? "0.0"
        guard let myAddressString = arrayOfAddresses.first else { return }
        let walletAddress = EthereumAddress(myAddressString)! // Your wallet address
        let toAddress = EthereumAddress(addressTextField.text!)!
        let contract = web3.contract(Web3.Utils.coldWalletABI, at: toAddress, 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 tx = contract.write(
            "fallback",
            parameters: [AnyObject](),
            extraData: Data(),
            transactionOptions: options)!
        print(tx.transaction)
        print(tx.contract)
        do {
            try tx.send()
            print("Successfuly Sent Transaction")
        } catch {
            print(error)
            print("Failed to Send Transaction")
        }
        self.dismiss(animated: true)
    }

And It prints:

typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: “Expected to decode Array<Any> but found a dictionary instead.”, underlyingError: nil))

What’s wrong?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Emin-Eminicommented, Jul 1, 2022

Alright, what was the final fix for me was calling tx.send() with password.

So:

try tx.send(password: "yourPassword", transactionOptions: options)

0reactions
Emin-Eminicommented, Jul 1, 2022

@elapovski @friendlynandy

I added KeystoreManager to Web3, but stil is not working.

let web3 = Web3.InfuraMainnetWeb3()
var keystoreManager: KeystoreManager!
func setupWallet() {
        let keychainMnemonicsString = KeychainWrapper.standard.string(forKey: "walletMnemonics")
        let keychainWalletName = KeychainWrapper.standard.string(forKey: "walletName")
        let keychainWalletPassword = KeychainWrapper.standard.string(forKey: "spendingPassword")
        guard let mnemonics = keychainMnemonicsString else { return }
        guard let name = keychainWalletName else { return }
        guard let password = keychainWalletPassword else { return }
        
        let keystore = try! BIP32Keystore(
            mnemonics: mnemonics,
            password: password,
            mnemonicsPassword: "",
            language: .english)!
        
        let keyData = try! JSONEncoder().encode(keystore.keystoreParams)
        let address = keystore.addresses!.first!.address
        let wallet = Web3Wallet(address: address, data: keyData, name: name, isHD: true)
        
        let data = wallet.data
        
        let keystoreDataBIP32 = BIP32Keystore(data)!
        keystoreManager = KeystoreManager([keystoreDataBIP32])
        
        web3.addKeystoreManager(keystoreManager)
    }

Then I called the signTransaction() function as mentioned above.

But now the error is:

inputError(desc: “Failed to locally sign a transaction”)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix problems sending or receiving money - Google Pay Help
Step 1: Check for an active internet connection. Transactions can't be made offline. If no: Try again when you're connected to the internet....
Read more >
ethereum send transaction is not working?
1 Answer 1 · Hey, I tried the above solution but I am not getting. I am printing the accounts log.The problem is...
Read more >
If you can't send or receive money with Apple Cash
If you try to use Apple Cash to send or receive money and need help, try these steps. First, check the Apple System...
Read more >
Send transaction functionality is not working · Issue #75 - GitHub
I have integrated wallet connect v1.0 to my android application. The functionality of requesting for connection and accepting connection is ...
Read more >
Sending a signed transaction is not working - Web3 / Node.js
js using the web3 library. I have tried many pieces of code but I get the same issues every time: The transaction hash...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found