This guide will show you how to use our API to trigger your first reward. We are going to reward a user some XP.

1

Get your API Key

Firstly, you will need an API Key. If you haven’t already generated one, head over to Get an API Key.

2

Request the transaction

curl --request POST \
--url https://api.openformat.tech/v1/reward/XP \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <x-api-key>' \
--data '{
"app_id": "0x456",
"action_id": "share_tweet",
"receiver": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"amount": 123
}'
3

Sign the Transaction

By default, the app owner is the only person who has permission to reward tokens and badges from a specific app. Make sure the transaction is signed with the app owner account.

import { privateKeyToAccount } from 'viem/accounts';

const account = privateKeyToAccount('0x...');

const unsignedTransactionFromAPI = response.unsignedTransaction;

const signed = await account.signTransaction(unsignedTransactionFromAPI);

console.log(signed);
//0x02f90155830138818208438459682f008459682f1283012f639446f518c0fb5ab62e1212b4b31b3d68765e01c42b80b8e4609512c9000000000000000000000000610e0d04ca919e65db1f89c23d0969d1c98445c100000000000000000000000003755352654d73da06756077dd7f040adce3fd580000000000000000000000000000000000000000000000004563918244f4000062616e616e610000000000000000000000000000000000000000000000000000414354494f4e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000c001a023920682be1c65841977c0b0a41b0eb53f42a060dcd99ee62ede42b0670c958da05594095e5d5dffab298acf06f3e1b19c8ffda0a482e562d438e2cb11becb675e

4

Execute the Transaction

curl --request POST \
  --url https://api.openformat.tech/v1/transactions/execute \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: <x-api-key>' \
  --data '{
  "signed_transaction": "0x02f901558301388182084384596......"
}'