Ask or search…


Create Stream

The create stream endpoint requires the sender to transfer the streamed token to the CoinDrip smart contract. If the transaction is successful, the stream is registered on the blockchain. As soon as the start time is reached, the CoinDrip protocol will unlock tokens for the recipient.
fn create_stream(
recipient: ManagedAddress,
start_time: u64,
end_time: u64,
can_cancel: OptionalValue<bool>
You must also send the token you want to stream in the create stream transaction.
The start_time must be bigger than self.blockchain().get_block_timestamp(), or the transaction will fail.
Example of building a create stream transaction payload using mx js sdk:
.setFunction(new ContractFunction("ESDTTransfer"))
.addArg(new BytesValue(Buffer.from('USDC-a2sd58', "utf-8"))) // streamed token identifier
.addArg(new BigUIntValue(TokenPayment.egldFromAmount('100').valueOf())) // streamed token amount
.addArg(new BytesValue(Buffer.from("createStream", "utf-8")))
.addArg(new AddressValue(new Address('erd1aaaa.....'))) // recipient address
.addArg(new U64Value(1674158572)) // start time
.addArg(new U64Value(1674159572)) // end time

Claim from stream

This endpoint transfers the amount of already streamed tokens from the CoinDrip smart contract to the recipient's wallet.
fn claim_from_stream(
stream_id: u64
The recipient of the stream can only call this endpoint after the present time went over the start time of the stream.
Example of building a claim from stream transaction payload using mx js sdk:
.setFunction(new ContractFunction("claimFromStream"))
.addArg(new U64Value(12)) // stream id

Cancel stream

This endpoint can be called by the sender or the recipient and will cancel a stream at any time if the stream was not marked as non-cancellable by the sender during creation. If the stream is canceled before the start time, all funds are returned to the sender. If you cancel the stream after the start time, but before the end time, the amount that was streamed so far is transferred to the recipient, and the remaining tokens come back to your wallet. If the stream is canceled after the end time, all funds are transferred to the recipient.
fn cancel_stream(
stream_id: u64,
with_claim: OptionalValue<bool>
If you call this endpoint with the "with_claim" param "true", it will also claim your remaining funds (if any) after the cancellation.
Example of building a cancel stream transaction payload using mx js sdk:
.setFunction(new ContractFunction("cancelStream"))
.addArg(new U64Value(9)) // stream id

Claim from stream after cancel

After a stream is canceled, you can call this endpoint to claim the streamed tokens as a recipient or the remaining tokens as a sender (if any). This endpoint is especially helpful when the recipient/sender is a non-payable smart contract.
For convenience, this endpoint is automatically called by default from the Cancel stream endpoint (is not instructed otherwise by the "with_claim" param).
fn claim_from_stream_after_cancel(
stream_id: u64
Example of building a claim from steram after cancel transaction payload using mx js sdk:
.setFunction(new ContractFunction("claimFromStreamAfterCancel"))
.addArg(new U64Value(9)) // stream id
Last modified 9mo ago