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

Signing Transactions Offline #116

Closed
emkman opened this issue Apr 24, 2018 · 5 comments · Fixed by #279
Closed

Signing Transactions Offline #116

emkman opened this issue Apr 24, 2018 · 5 comments · Fixed by #279

Comments

@emkman
Copy link

emkman commented Apr 24, 2018

Support for signing transactions offline for sending to a locked node or potentially Infura would be extremely helpful. Similar functionality can be found in the ethereumjs-tx for javascript. Much of this functionality exists across the parity codebase and needs to be pieced together. In discussing this with @tomusdrw, the general steps required would be:

  1. Encode contract call (this can be done by ethabi)
  2. Create and fill a transaction request (nonce, gas, gasprice, etc) - I believe there is an RPC method to do that in Parity
  3. Encode the transaction into RLP
  4. Calculate hash and sign (this could be done by ethkey library)
  5. Broadcast signed transaction
@synlestidae
Copy link
Contributor

synlestidae commented Aug 23, 2018

EDITED

Been interested in having this functionality since I came across the web3 crate.

We could implement web3::api::Eth::sign_transaction. Or maybe create a RawTransaction struct with a sign method. When I first made this issue I thought we just need to utilise web3.eth.accounts.signTransaction. Turns out offline signing is not even supported by the web3.js project.

@synlestidae
Copy link
Contributor

The output of sign_transaction would be the RLP-encoded transaction that can be fed into send_raw_transaction.

synlestidae added a commit to synlestidae/rust-web3 that referenced this issue Aug 24, 2018
synlestidae added a commit to synlestidae/rust-web3 that referenced this issue Aug 25, 2018
@tomusdrw
Copy link
Owner

Most likely integrate with https://github.com/tomusdrw/ethsign

@steveswing
Copy link
Contributor

Most likely integrate with https://github.com/tomusdrw/ethsign

We used ethsign with web3 indirectly -- in https://github.com/SubstratumNetwork/SubstratumNode -- but had to copy RawTransaction to work around type conflicts between web3::types, ethereum-types, and primitive-types.

@tomusdrw
Copy link
Owner

@steveswing cool! Yeah, there is no proper transaction type around (except for parity repo, but you really don't want to reference that in your code). I also wanted to avoid it in ethsign (initially), but would be happpy to include it at some point, along with different signature payloads that Ethereum is using (signData, signTransaction, etc)).

fleupold added a commit to gnosis/dex-services that referenced this issue Oct 10, 2019
This PR introduces functionality to sign transactions by the driver in rust before submitting them to the ethereum client.

This is needed to deploy our system on rinkeby and mainnet since there we don't have "unlocked" clients (such as ganache for testing). Therefore our transactions are rejected as invalid.

Unfortunately our rust web3 library didn't have built in support for this (there is an open issue but not yet an implementation tomusdrw/rust-web3#116).

With this change, we now provide the network id and private key in our env file and sign the raw transaction using the `ethereum-tx-sign` library. This will make the system work with both unlocked and locked accounts.

### Test Plan

In common.env set `NETWORK_ID` to 4, `PRIVATE_KEY` to your rinkeby eth funded account's pk, `STABLEX_CONTRACT_ADDRESS` to `0x9046451F7cF124c1d7d1832F76F5e98a33D1610E`

`docker-compose up`

Then use the truffle scripts to add tokens, deposits and orders (note that you will have to make a trade happen for the driver to actually send a transaction).

Alternatively, you can remove this if check 
https://github.com/gnosis/dex-services/blob/89448372eab3a860ecdf673607acbf54f05d4d0f/driver/src/driver/stablex_driver.rs#L42
to make it also submit trivial solutions.

See transaction going through successfully.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants