Initialize Token Stream

const now = nowInSec();
const streamRate = FungibleTokenAmount.parse("0.0001", 18).toString();
const startTime = (now + 10).toString();
const endTime = (now + 400).toString(); // 5 min
const receiver = "receiverAccountId.testnet";
const canCancel = true;
const canUpdate = true;
const tokenId = "usdc.fakes.testnet";

const streamParams: InitTokenStreamParams = {
   streamRate,
   startTime,
   endTime,
   receiver,
   canCancel,
   canUpdate,
   tokenId,
};

const streamPayload = await client.initTokenStream(streamParams);

const results = await wallet.signAndSendTransactions(streamPayload);

For obtaining streamId, you can do in the following way.

const receipts = result.receipts_outcome;
if (receipts) {
   const receipt = receipts.find(
   (receipt) => receipt !== undefined && (receipt.outcome as any).executor_id == _contractId,
);
let streamId = "";
if (receipt) {
   const evenLog = receipt.outcome.logs.find((log) => log.includes("Token stream created"));
   if (evenLog) {
	const json = evenLog.substring(11);
	streamId = JSON.parse(json).data.stream_id.toString();
   }
}

Last updated