Skip to content

reward.useStart

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

Usage

ts
import {  } from 'wagmi/tempo'
import {  } from 'viem'

const  = ..()

// Call `mutate` in response to user action (e.g. button click, form submission)
.({
  : ('1000'),
  : '0x20c0000000000000000000000000000000000000',
})

.('Stream ID:', .?.)
.('Amount:', .?.)
Stream ID: 1n
Amount: 1000000000000000000000n
ts
import { createConfig, http } from 'wagmi'
import { tempoTestnet } from 'wagmi/chains'
import { KeyManager, webAuthn } from 'wagmi/tempo'

export const config = createConfig({
  connectors: [
    webAuthn({
      keyManager: KeyManager.localStorage(),
    }),
  ],
  chains: [tempoTestnet],
  multiInjectedProviderDiscovery: false,
  transports: {
    [tempoTestnet.id]: http(),
  },
})

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.distribute action and wait for inclusion manually:

ts
import { Hooks } from 'wagmi/tempo'
import { Actions } from 'viem/tempo'
import { parseEther } from 'viem'
import { useWaitForTransactionReceipt } from 'wagmi'

const start = Hooks.reward.useStart()
const { data: receipt } = useWaitForTransactionReceipt({ hash: start.data })

// Call `mutate` in response to user action (e.g. button click, form submission)
start.mutate({
  amount: parseEther('1000'),
  token: '0x20c0000000000000000000000000000000000000',
})

if (receipt) {
  const { args: { id, funder, amount } }
    = Actions.reward.start.extractEvent(receipt.logs)

Return Type

See TanStack Query mutation docs for more info hook return types.

data

See Wagmi Action reward.start Return Type

mutate/mutateAsync

See Wagmi Action reward.start Parameters

Parameters

config

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

mutation

See the TanStack Query mutation docs for more info hook parameters.

Action

Released under the MIT License.