Skip to content

reward.start

Starts a new reward stream that distributes tokens to opted-in holders.

Usage

Use the reward.start action on the Viem client to start a reward distribution stream.

example.ts
import { parseEther } from 'viem'
import { client, token } from './viem.config'
 
const { amount, durationSeconds, funder, id, receipt } =
  await client.reward.startSync({
    amount: parseEther('1000'),
    token,
  })
 
console.log('Stream ID:', id)
Stream ID: 1n
console.log('Amount:', amount)
Amount: 1000000000000000000000n
console.log('Duration:', durationSeconds, 'seconds')
Duration: 2592000 seconds

Asynchronous Usage

The example above uses a *Sync variant of the action, that will wait for the transaction to be included before returning.

If you are optimizing for performance, you should use the non-sync reward.start action and wait for inclusion manually:

import { Actions } from 'tempo.ts/viem'
import { parseEther } from 'viem'
import { client, token } from './viem.config'
 
const hash = await client.reward.start({
  amount: parseEther('1000'),
  token,
})
const receipt = await client.waitForTransactionReceipt({ hash })
 
const { args: { id, funder, amount, durationSeconds } } 
  = Actions.reward.start.extractEvent(receipt.logs)

Return Type

type ReturnType = {
  /** Total amount allocated to the stream */
  amount: bigint
  /** Duration of the stream in seconds (0 for immediate distributions) */
  durationSeconds: number
  /** Address that funded the stream */
  funder: Address
  /** Unique stream ID (0 for immediate distributions; all that is currently supported) */
  id: bigint
  /** Transaction receipt */
  receipt: TransactionReceipt
}

Parameters

amount

  • Type: bigint

The amount of tokens to distribute. Must be greater than 0.

token

  • Type: Address

Address of the TIP-20 token.

account (optional)

  • Type: Account | Address

Account that will be used to send the transaction.

feeToken (optional)

  • Type: Address | bigint

Fee token for the transaction.

Can be a TIP-20 token address or ID.

feePayer (optional)

  • Type: Account | true

Fee payer for the transaction.

Can be a Viem Account, or true if a Fee Payer Service will be used.

gas (optional)

  • Type: bigint

Gas limit for the transaction.

maxFeePerGas (optional)

  • Type: bigint

Max fee per gas for the transaction.

maxPriorityFeePerGas (optional)

  • Type: bigint

Max priority fee per gas for the transaction.

nonce (optional)

  • Type: number

Nonce for the transaction.

nonceKey (optional)

  • Type: 'random' | bigint

Nonce key for the transaction. Use 'random' to generate a random nonce key.

validBefore (optional)

  • Type: number

Unix timestamp before which the transaction must be included.

validAfter (optional)

  • Type: number

Unix timestamp after which the transaction can be included.

throwOnReceiptRevert (optional)

  • Type: boolean
  • Default: true

Whether to throw an error if the transaction receipt indicates a revert. Only applicable to *Sync actions.