Working with Staking

Socios.com users have two possibilities when staking do in-app:

  • Staking Fan Tokens.

  • Staking CHZ.

Furthermore, Socios.com partners can implement the Socios.com Fan Token staking mechanism on their own website.

This page contains sample code to achieve that.

About "Stake & Earn"

By staking their Fan Tokens through their Socios.com Wallet, Socios.com users can earn Reward Points on a daily basis, and possibly get quick access to great Socios.com rewards and activities!

Each staked Fan Token will join an existing pool of rewards points, made of all the Fan Tokens staked by all Socios.com users.

The pool then works for all users, and the more Fan Tokens you have staked, the more reward points you can obtain in return.

Fan Token staking is also possible from wallets other than Socios.com Wallet.

This allows anyone to contribute to the Fan Token ecosystem, but staking from non-Socios wallets cannot earn Socios.com reward points.

Implementing Socios.com staking/unstaking on your own site

Socios.com partners can implement Fan Token staking right into their own platform.

This is done through a specific smart contract created by the Socios.com team. This Staking smart contract has 5 main features:

  • Staking

  • Locking

  • Processing the locks

  • Unstaking

  • Claiming

To implement staking, unstaking, and the other necessary fixtures, we provide you with the following sample code listing, ready for you to adapt to your own codebase.

Prerequisite: StakingABI JSON file

Setting up your Chiliz Viem Client

import { createPublicClient, http, createWalletClient } from 'viem'
import { chiliz, spicy } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts';

const publicClient = createPublicClient({
	chain: chiliz, // chiliz (mainnet) or spicy (testnet)
	transport: http() // you can overwrite the transport URL provided by Chain object here 
})

const privateKey = '0xSenderPrivateKey'; // Replace with the sender's private key
const account = privateKeyToAccount(privateKey);
const walletClient = createWalletClient({
	account: '0x',
	chain: chiliz, // chiliz (mainnet) or spicy (testnet)
	transport: http()
})

Staking

import stakingABI from './StakingABI.json';

async function stake(amount, tokenAddress) {
  const txHash = await walletClient.writeContract({
    address: '0xFanTokenStakingAddress', // Replace with the Fan Token Staking contract address
    abi: stakingABI,
    functionName: 'stake', // Function to stake tokens
    args: [amount, tokenAddress],
  });
  return publicClient.waitForTransactionReceipt({ hash: txHash });
}

// Example usage. Replace 10 with the exact amount to stake, and 0xFanTokenAddress with the actual Fan Token contract address.
stake(10, '0xFanTokenAddress',).then(console.log);

Knowing what's staked

import stakingABI from './StakingABI.json';

async function getStakeDataLatest(staker, fanToken, perEventType) {
  const stakeData = await publicClient.readContract({
    address: '0xFanTokenStakingAddress', // Replace with the Fan Token Staking contract address,
    abi: stakingABI,
    functionName: 'getStakeDataLatest',
    args: [staker, fanToken, perEventType],
  });
  return stakeData;
}

// Example usage, Replace 0xStakerWalletAddress with the actual staker wallet address, and 0xFanTokenAddress with the actual Fan Token contract address.
getStakeDataLatest('0xStakerWalletAddress', '0xFanTokenAddress').then(console.log);

Unstaking

import stakingABI from './StakingABI.json';

async function unstake(amount, tokenAddress) {
  const txHash = await walletClient.writeContract({
    address: '0xFanTokenStakingAddress', // Replace with the Fan Token Staking contract address
    abi: stakingABI,
    functionName: 'unstake', // Function to unstake tokens
    args: [amount, tokenAddress],
  });
  return publicClient.waitForTransactionReceipt({ hash: txHash });
}

// Example usage. Replace 10 with the exact amount to unstake, and 0xFanTokenAddress with the actual Fan Token contract address.
unstake(10, '0xFanTokenAddress',).then(console.log);

Checking the cooldown period

import stakingABI from './StakingABI.json';

async function getCooldownPeriod() {
  const cooldownPeriod = await publicClient.readContract({
    address: '0xFanTokenStakingAddress', // Replace with the Fan Token Staking contract address,
    abi: stakingABI,
    functionName: 'unstakePeriod', // The function that returns the unstake period.
    args: [],
  });
  return cooldownPeriod.toString();;
}

// Example usage.
getCooldownPeriod().then(console.log);

Claiming (after cooldown period)

import stakingABI from './StakingABI.json';

async function claim(amount, tokenAddress) {
  const txHash = await walletClient.writeContract({
    address: '0xFanTokenStakingAddress', // Replace with the Fan Token Staking contract address
    abi: stakingABI,
    functionName: 'claim', // Function to claim tokens
    args: [amount, tokenAddress],
  });
  return publicClient.waitForTransactionReceipt({ hash: txHash });
}

// Example usage. Replace 0xFanTokenAddress with the actual Fan Token contract address.
claim('0xFanTokenAddress',).then(console.log);

Last updated