Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Problem with signing/sending transactions #8

Closed
CrisESC93 opened this issue Feb 6, 2018 · 8 comments
Closed

Problem with signing/sending transactions #8

CrisESC93 opened this issue Feb 6, 2018 · 8 comments

Comments

@CrisESC93
Copy link

CrisESC93 commented Feb 6, 2018

Hello!!!

I have some doubts how sign and send transactions, for example I have something like this:

guard
    let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first,
    let keystore = KeystoreManager.managerForPath("\(path)/KeyStore"),
    let url = URL(string: "http://localhost:8545"),
    let web3 = Web3.newWeb3(url)
else {
    return
}

web3.addKeystoreManager(keystore)
        
let accountAddress = EthereumAddress("0xDa6Db68eF4f0796c7d8C1D53b3F4C4ecA8F1c589")
let contractAddress = EthereumAddress("0x0ecaaeaa9a81d7fe6b685f0f7042c6733e8d4ac4")
let abi = "..."
var options = Web3Options()

options.from = accountAddress
options.gas = BigUInt(3000000)

let params = ["One", "Two", accountAddress] as [AnyObject]

guard
    let contract = web3.contract(abi, at: contractAddress),
    let intermediate = contract.method("myMethod", parameters: params, options: options)
else {
    return
}

if let result = intermediate.send(password: "myPassword", options: nil) {
    print("Response:\n\(result)")
}
else {
    print("No response")
}

But the console show me:

["id": 1517959159, "result": 0x0, "jsonrpc": 2.0]
["id": 1517959159, "result": 0x1c3e2, "jsonrpc": 2.0]
Signature required 0 rounds
Transaction
Nonce: 0
Gas price: 5000000000
Gas limit: 3000000
To: 0x0ECAAeaA9a81D7fe6B685F0f7042c6733e8D4aC4
Value: 0
Data: 0xcd6caf44516d634d4d466e4a33484e5056674e56683745547a33694c4c4e78575964563941414279464e66327238524d6670000000000000000000000000000000000000000000000000000000000000da6db68ef4f0796c7d8c1d53b3f4c4eca8f1c589
v: 66701
r: 84777281406398303591956306169653691463836343481459907963146828151300907793144
s: 46714626519332337577713737081164370614021019176989393775749382342225642067890
Intrinsic chainID: Optional(33333)
Infered chainID: Optional(33333)
sender: Optional(web3swift.EthereumAddress(_address: "0xda6db68ef4f0796c7d8c1d53b3f4c4eca8f1c589"))

["id": 1517959159, "jsonrpc": 2.0]
No response

I saw the example (Send on Rinkeby) and this issue but when I try to implement something like that doesn't works.

I hope can you help me.
Thanks.

@shamatar
Copy link
Contributor

shamatar commented Feb 7, 2018

Hello @CrisESC93

I see that a signature was done correctly, although no response was received after sending raw transaction. Would you try to put a debug breakpoint there and see what actually happens. Also, what Ethereum node do you use for testing? Chain ID of 33333 is quite high, and web3swift enforces EIP155, so may be the node just rejects such transaction.

Sincerely, Alexander

@CrisESC93
Copy link
Author

CrisESC93 commented Feb 7, 2018

Hello @shamatar

Thanks for answer me. Now I'm working with a private node created by the blockchain developers with which I'm working now, so I don't know if that make problems?

Also I commented to them your observation about the Chain ID, they gonna change this value and we try again another tests.

Update:
The rare of the situation is if I use the method 'call' in place of 'send':

let params = [accountAddress] as [AnyObject]

guard
    let contract = web3.contract(abi, at: contractAddress),
    let intermediate = contract.method("balanceOf", parameters: params, options: options)
else {
    return
}

if let response = intermediate.call(options: nil) {
    print("Response:\n\(response)")
}
else {
    print("No Response")
}

I receive a response:

["id": 1518025152, "result": 0x00000000000000000000000000000000000000000000000000000000000f4240, "jsonrpc": 2.0]
Response:
["0": 0, "balance": 1000000]

Thanks.

@shamatar
Copy link
Contributor

shamatar commented Feb 7, 2018

Hello @CrisESC93

From "call" test I'd say parameters are encoded and processed correctly (I assume you are running on the same network/node). If EIP155 is not supported on your local test net - it can be an issue, what you can do is try to set web3.provider.network = nil.

I see a problem in my dependency chaining for transactions, and I'll make it easier to disable of EIP155, but will take a day or two.

Sincerely, Alexander

@CrisESC93
Copy link
Author

Hello @shamatar

Thanks for answer.
When I try to set the nil value to web3.provider.network Xcode tells me is a just "get-only property".

The blockchain developers tells me it's probably that not configured (and maybe they will not try to use it because they wanna create a private blockchain).

Also I have a another doubt, how can get the decoded private key? Because they wanna implement the import/export from this key.

Thanks for your help.

@shamatar
Copy link
Contributor

shamatar commented Feb 7, 2018

Hello @CrisESC93

Unsafe functions (like exposing unencrypted key for any time other than signing) were forbidden and not implemented by design. For your particular dial I'd recommend to either export a keystore JSON file to your computer and unarchive it using one of the public utilities, it's a standard Geth keystore format, version 3. Otherwise you can edit the source and make a decryption function declaration public.

Sincerely, Alexander

@CrisESC93
Copy link
Author

Hello @shamatar

Thanks for the advice, so for now I'm will start to work with the function to get the private key.

I hope the new version of the library can be works with our node, meanwhile I convinced to the blockchain developers to try implement the EIP155 and let me do tests. As soon as I get the results I'll post them here.

Thanks for your help.

@shamatar
Copy link
Contributor

shamatar commented Feb 9, 2018

Hello @CrisESC93

I've decided to implement this UNSAFE method for user convenience, as well as an ability to disable EIP155 by an extra call. It'll come with a massive overhaul of 0.3 release in the next week.

Sincerely, Alexander

@CrisESC93
Copy link
Author

Hello @shamatar

After having done many tests, the transactions work. We discovered that there were problems with the node, which we are still solving (for example we continue to find out about sending errors).

The only problem I had when sending transactions with the method:

intermediate.send(password: "MyPassword", options: nil)

is that it no longer signs more than one transaction per account, so I decided to sign with the method:

keystoreManager.signTX(transaction: &intermediate.transaction, password: "MyPassword", account: EthereumAddress("0x..."))

and send the transaction with the method:

intermediate.sendSigned()

And with these steps the transactions are signed and sent correctly.

Thanks Alexander.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants