This folder contains a Soroban smart contract example for a payment channel. A payment channel is a smart contract that acts as a mediator between a person who wants to make a payment and another who has to receive that payment, in order to provide more security when carrying out the transaction.
Function Name | Parameters | Return Type | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
initialize |
|
Result<PaymentChannelState, PCError> |
Initializes a new payment channel with provided parameters. | ||||||
close |
|
Result<(), PCError> |
Allows the recipient to close the channel and withdraw funds. Unclaimed funds will go back to the sender. | ||||||
withdraw |
|
Result<(), PCError> |
Allows the recipient to withdraw funds incrementally from the channel. | ||||||
set_expiration |
|
Result<(), PCError> |
Sets the expiration timestamp of the channel. | ||||||
claim_timeout |
|
Result<(), PCError> |
Allows the sender to claim funds if the channel has expired. | ||||||
get_recipient_address |
|
Result<Address, PCError> |
Retrieves the recipient's address associated with the payment channel. | ||||||
get_sender_address |
|
Result<Address, PCError> |
Retrieves the sender's address associated with the payment channel. | ||||||
modify_allowance |
|
Result<(), PCError> |
Allows the sender to modify the permitted maximum amount to be withdrawn by the recipient (considering the sum of all partial extractions). | ||||||
get_state |
|
Result<PaymentChannelState, PCError> |
Retrieves the current state of the payment channel. |
-
Initialization of Payment Channel: Use the
initialize
function to initialize a new payment channel by providing the required parameters, such as sender address, recipient address, close duration, and token address. -
Making an Initial Payment: Deposit funds into the payment channel by sending the desired amount to the contract.
-
Partial Fund Withdrawal: Make partial withdrawals of funds using the withdraw function.
-
Closing the Payment Channel: Close the channel and receive the remaining funds using the
close()
function and providing the desired amount.
Set Expiration: The sender can set an expiration time for the channel using the set_expiration()
function if desired.
Claim Timeout: If the channel has expired and the funds have not been claimed, the sender can claim the remaining funds using the claim_timeout()
function.
👉 Navigate to this link to view the security review.