HTCL (Hashed Timelock Contracts) on Ethereum Virtual Machine (EVM) ERC tokens.
This contract provides a way to create and keep HTLCs for ETH.
See HashedTimelockERC20.sol for a contract that provides the same functions for ERC20 tokens.
- newContract(receiver, hashlock, timelock) - a sender calls this to create a new HTLC and gets back a 32 byte contract id
- withdraw(contractId, preimage) - once the receiver knows the preimage of the hashlock hash they can claim the ETH with this function
- refund() - after timelock has expired and if the receiver did not withdraw funds the sender / creator of the HTLC can get their ETH back with this function.
You can find the full contract verified & published on ether.
function newContract(address payable receiver, bytes32 hashLock, uint32 timeLock) external payable returns (bytes32 contractId)
Sender sets up a new hash time lock contract depositing the ETH and providing the receiver lock terms.
|receiver||address payable||Receiver of the ETH.|
|hashLock||bytes32||A keccak256 hash hashlock.|
|timeLock||uint32||UNIX epoch seconds time that the lock expires at. Refunds can be made after this time.|
|contractId||bytes32||Id of the new HTLC. This is needed for subsequent calls.|
function withdraw(bytes32 contractId, bytes32 preimage) external returns (bool)
Called by the receiver once they know the preimage of the hashlock. This will transfer the locked funds to their address.
|contractId||bytes32||Id of the HTLC.|
|preimage||bytes32||keccak256(_preimage) should equal the contract hashlock.|
|||bool||bool true on success|
function refund(bytes32 contractId) external returns (bool)
Called by the sender if there was no withdraw AND the time lock has expired. This will refund the contract amount.
|contractId||bytes32||Id of HTLC to refund from.|
|||bool||bool true on success|
function getContract(bytes32 contractId) external view returns (uint256, bytes32, bytes32, uint32, address, address, bool)
Get contract details.
|contractId||bytes32||HTLC contract id|
function haveContract(bytes32 contractId) internal view returns (bool)
Is there a contract with id _contractId.
|contractId||bytes32||Id into contracts mapping.|
function getEmptyContractHash() private pure returns (bytes32)
This method return a keccak256 hash of an empty Lock contract.
function getCollectedFee() external view returns (uint256)
Returns the total fee collected on this smart contract
function withdrawCollectedFee() external
This method will help user to withdraw the fee collected on this smart contract, it will only let the user to withdraw any fee not the balance of this smart contract as the balance might have some amount from the contract which has been locked.
function updateFeeReceiver(address feeReceiverAddress) external
This method will update the feeReceiver address who can withdraw the fee collected on this smart contract
|feeReceiverAddress||address||- address of new fee collector|
function updateOwner(address ownerAddress) external
This method will update the owner address on this smart contract
|ownerAddress||address||- address of new owner|
function updateFee(uint32 updatedFeeNumerator, uint32 updatedFeeDenominator) external
This method will allow owner to update the fee charged upon successful withdrawal
|updatedFeeNumerator||uint32||- new fee numerator|
|updatedFeeDenominator||uint32||- new fee denominator|