I'm new to working with Ethereum smart contracts and would appreciate some guidance by the community on a task that I'm trying to solve.

This is the contract I want to use - https://github.com/chatch/hashed-timelock-contract-ethereum/blob/master/contracts/HashedTimelock.sol

For the sake of the questions, let's focus on two users - Alice and Bob. Alice has some data that Bob wants. Bob uses the HTLC to retrieve that data from Alice in exchange for some tokens.

I'm playing around with the idea of Alice not having to actively be involved in this process and allow her part of the transaction to be delegated to some automated process. The part I'm stuck on is the signing of the transaction.

Alice needs to call the withdraw function in the HTLC. If I create an application that does this process for Alice, I see a few options:
1. The process has access to Alice's private key so that it can send a signed transaction with the data to the withdraw function.
2. A temporary address is created by the process for Alice. This temp address is sent to Bob and using this address, the HTLC is created. This way, the process I create only has access to the temp private key and not Alice's permanent address' private key.
3. (Not sure if this is feasible) An unsigned transaction is used to call withdraw so that the process does not need access to Alice's private key. Only the data to be sent is needed for the contract to be satisfied.

While testing this with Ganache I did not need to sign any transactions, I assume Ganache handled this. What is a good way to achieve this on main net?


A problem with step 3 is that you reveal the hash when you send your transaction. Then anyone will be able to submit their own transaction with higher gas price and beat you, ie front running.

A possible solution if for Alice to authorize the temp address. But it is not ideal because it requires an extra transaction from Alice.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.