immutability-io / vault-ethereum

A plugin that turns Vault into an Ethereum wallet.
244 stars 66 forks source link

/accounts/:name/sign not producing valid signed transactions #43

Closed A-w-K closed 6 years ago

A-w-K commented 6 years ago

Detailed Description

I would like to use vault-ethereum to sign raw transactions that can then be broadcast. I am trying to sign my transaction like this:

curl -k --header "X-Vault-Token: $TOKEN" \
    --request POST \
    --data '{"to":"0xSOME_ADDRESS","value":"100000","gas":"2000000","gasPrice":"234567897654321","nonce":"0","chainId":"3"}' \
    https://localhost:8200/v1/ethereum/accounts/test/sign

unfortunately no matter what i put in the data field i always get the same signature

0xdaf75853fd0dff6da264b99f0d5f03dcd3d50e5f3ad01c05a20acdc08dc7f0b635d4ca71d3d3560d1a1878c948c32baec8c30965a75b500fb1d5c80e61ddcab700

and when i try to broadcast it using myetherwallet i get the error:

invalid rlp: total length is larger than the data

anyone got an idea what the issue here is or how i can proceed?

cypherhat commented 6 years ago

So, the sign endpoint is poorly documented. It just signs with a private key.

What you want to do is use the debit endpoint and set send=false:

So if you have a payload like:

{
  "amount":"200000000000000000",
  "to": "0x36D1F896E55a6577C62FDD6b84fbF74582266700"
  "send": false
}

Then you can use curl:

$ curl -s --cacert /etc/vault.d/root.crt --header "X-Vault-Token: $VAULT_TOKEN" \
    --request POST \
    --data @payload.json \
    https://localhost:8200/v1/ethereum/accounts/test2/debit | jq .

And in your response:

{
  "request_id": "b921207e-c0d9-a3c1-442b-ef8b1884238d",
  "lease_id": "",
  "lease_duration": 0,
  "renewable": false,
  "data": {
    "amount": "100000000000000000",
    "amount_in_usd": "0",
    "address_from": "0x4169c9508728285e8a9f7945d08645bb6b3576e5",
    "address_to": "0x8AC5e6617F65c071f6dD5d7bD400bf4a46434D41",
    "gas_limit": "21000",
    "gas_price": "1000000000",
    "signed_transaction": "0xf86b06843b9aca00825208948ac5e6617f65c071f6dd5d7bd400bf4a46434d4188016345785d8a0000802ca0ff3fccbde1964047db6be33410436a9220c91ea4080b0e14489dc35fbdabd008a0448fe3ec216a639e1b0eb87b0e4b20aab2e5ec46dad4c38cfc81a1c54e309d21",
    "starting_balance": 8460893507395267000,
    "starting_balance_in_usd": "0",
    "total_spend": "100000000000000000",
    "transaction_hash": "0x3a103587ea6bdeee944e5f68f90ed7b1f4c7699236167d1b1d29495b0319fb26"
  },
  "warnings": null
}

The signed_transaction can be sent.

A-w-K commented 6 years ago

Thank you for your response, I see this is working fine for normal transactions but what I would like to do is make a contract call. Unfortunately the /debit endpoint ignores the data property in the sent JSON.

var txData []byte
tx := types.NewTransaction(nonce, toAddress, amount, gasLimit, gasPrice, txData)

Is there any way to make a contract call using this plugin as of now?

A simple endpoint to sign a raw transaction in JSON format would be amazing!

cypherhat commented 6 years ago

Give this a try: https://github.com/immutability-io/vault-ethereum/pull/45

cypherhat commented 6 years ago

Closing due to a lack of response