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

I got an Error When I Using Sending ETH #242

Closed
haizhiwen opened this issue Feb 16, 2020 · 5 comments
Closed

I got an Error When I Using Sending ETH #242

haizhiwen opened this issue Feb 16, 2020 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@haizhiwen
Copy link

let mnemonicstr = "助记词"
let passWord = "password"
let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let bip32ks = try! BIP32Keystore(mnemonics: mnemonicstr, password: passWord)
let keydata = try! JSONEncoder().encode(bip32ks!.keystoreParams)
FileManager.default.createFile(atPath: userDir + "/bip32_keystore"+"/key.json", contents: keydata, attributes: nil)
let web3Main = Web3.InfuraMainnetWeb3() //or any other network
let price = "0.0002"
let fromAddress = bip32ks?.addresses?.first?.address
let toAddress = "0xb7c54ABc6Af1862A69fb467C47F54e521CC7c00E"
let destinationEthAddress = EthereumAddress(toAddress)!
let ethAddressFrom = EthereumAddress(fromAddress!)!
let contract = web3Main.contract(Web3Utils.coldWalletABI, at: destinationEthAddress, abiVersion: 2)
var options = TransactionOptions.defaultOptions
options.from = ethAddressFrom
options.value = Web3Utils.parseToBigUInt(String.init(price),units: .eth)
options.gasPrice = .automatic
options.gasLimit = .automatic
let writeTX = contract!.write("fallback", parameters: [], extraData: Data.init(), transactionOptions: options)!
writeTX.transactionOptions = options
do {
let sendingResult = try writeTX.send(password: passWord, transactionOptions: options)
print(sendingResult)
} catch let error {
print("sendingresult error 2")
print(error)
}

This is my code. I executed it directly in didFinishLaunchingWithOptions. After creating the wallet, I transferred it to toAddress and got error: typeMismatch (Swift.Array , Swift.DecodingError.Context (codingPath: [], debugDescription: " Expected to decode Array but found a dictionary instead. ", UnderlyingError: nil))
What should I do, I see in # 239 you said that the code runs without error.

@skywinder skywinder added the duplicate This issue or pull request already exists label Feb 16, 2020
@skywinder
Copy link
Collaborator

Duplicate of #239

@skywinder skywinder marked this as a duplicate of #239 Feb 16, 2020
@skywinder
Copy link
Collaborator

Hello. looks like it's the same issue with geth client as described #241 and #239

@skywinder
Copy link
Collaborator

skywinder commented Feb 16, 2020 via email

@haizhiwen
Copy link
Author

What I said is that some people say that this code works correctly, but I can't do it here. If I run this code, I get an error.

@skywinder
Copy link
Collaborator

skywinder commented Feb 17, 2020

There is some API changes. The code doesn't work with the latest infura api . We are digging into it. lets move the conversation to the initial issue

Closing it in favor of #239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants