Circle Internet Financial
Circle Internet Financial Logo

Sep 23, 2024

March 14, 2024

Leveraging Smart Contracts to Manage Loyalty Points

what you’ll learn

Leveraging smart contracts for blockchain loyalty programs can help foster innovative experiences and enable brands to expand their reach. Learn more.

Leveraging Smart Contracts to Manage Loyalty Points

Leveraging smart contracts for blockchain loyalty programs can help foster innovative experiences and enable brands to expand their reach.

Why Bring Loyalty Programs On-Chain

Loyalty programs are very popular. And no wonder—the global loyalty market size is said to be 5.57 billion USD and 70% of consumers say that loyalty programs are a leading factor in their purchasing decisions. Large consumer enterprises such as American Express and Marriott can attribute much of their success in customer engagement and revenue per customer to their powerful loyalty programs.

Traditional loyalty programs that rely on a centralized database face challenges in terms of cross-brand collaboration. This is primarily due to the isolation of loyalty points within a closed system, making it difficult for brands to collaborate with each other. However, if loyalty points are brought on-chain, brands can easily access an open-source ledger to conduct collaboration campaigns effortlessly. This shift to on-chain loyalty programs has the potential to foster innovative experiences and enable brands to expand their reach to other communities.

In this article, we’ll explore the benefits of using blockchain for loyalty program management. We’ll introduce Circle’s Smart Contract Platform which simplifies the deployment and management of smart contracts. We’ll look at the ERC-20 standard and why it’s perfect for loyalty points. Last, we’ll walk through the step-by-step process of creating our own ERC-20 token for loyalty points and show how to integrate it into your loyalty app.

Effortlessly Launch Your On-Chain Loyalty Program

The ERC-20 token standard is one of the most important standards in Ethereum (and EVM-compatible blockchains such as Polygon and Avalanche).

ERC-20 implements fungible tokens—digital assets where any one of that asset is identical to any other of the same asset. Fungible sounds complicated but in actuality, we deal with it every day when using money. A $100 bill is, for all intents and purposes, identical and exchangeable with any other $100 bill.

The ERC-20 standard requires that any implementing token include a set of common functions and events. This standardization is the core factor that makes interoperability, trade, and adoption of these tokens possible. Examples of these functions include:

  1. balanceOf: the wallet balance of the token in question
  2. totalSupply: the total number of tokens in circulation
  3. transfer: facilitates the transfer of the token from one wallet to another

ERC-20 tokens can be used for creating points in blockchain-based loyalty programs. As ERC-20 tokens, your points can now be managed digitally on blockchain. This means they can be held in Web3 wallets, easily exchanged between wallets, created and destroyed, and bought, sold and traded by your users worldwide. They can even be easily traded for other ERC-20 tokens, including other loyalty program points and Circle’s USDC. With your points on the blockchain, they are now secured by the underlying security of the chain itself.

Next let’s create and deploy an ERC-20 contract that implements points on blockchain. In this scenario, our loyalty program itself can be implemented as a Web3 dApp or a traditional Web2 app (we won’t cover those details in this article). We’ll focus instead on creating the points themselves as an ERC-20 contract, and then we’ll generate the “plug and play” code needed to work with those points from our loyalty program.

Step 1: Create a Circle Web3 Services Console Account

First, you’ll need a Circle Web3 Services Console account. If you don’t already have one, you can create one here.

image4-Mar-14-2024-12-53-42-1072-AM

Step 2: Create and deploy your on-chain contract

Next, navigate to the Circle Web3 Services Platform. On the left, you’ll see a menu with a list of services, including a section for Smart Contracts.

image2-Mar-14-2024-12-53-43-8570-AM

On this page, you can Import and Deploy smart contracts.

The Import functionality allows you to import any contract on any blockchain, and then interact with it by calling its functions. You would typically use this functionality for an app that will leverage USDC payments or for interacting with an existing protocol such as Uniswap.

For this article, instead of importing, we're going to create our own custom contract using the built-in and pre-audited templates, which can save you time and money.

Click on the Deploy button and you’ll see a pop-up like this:

image1-Mar-14-2024-12-53-42-5993-AM

Once you’ve clicked on the Ready to use Template option, you will see a window:

image7-4

There are three main token standards (ERC-20, ERC-1155, and ERC-721) currently available.

We want the ERC-20 or Token contract. This template was created by Circle and thirdweb—one of our partners.

You’ll be taken to the Token contract page which contains the details you need to create and deploy your ERC-20 contract. Take the time to read through the information. It includes information such as potential use cases, source code, callable functions, events transmitted, the audit report, and the GitHub repository where the latest changes are recorded.

Enter the token details

Now let’s enter our token details. Click on Deploy on the top right and fill out the form with the information about your token and the contract that powers it.

Note that if you don’t already have a wallet, you will create one when selecting the deployment details.

Click on Deploy again and you’ll be redirected to the main page of the Smart Contract Platform (SCP). Here you’ll see the deployment status of your contract.

Once deployed, you should see a new page for your smart contract.

Let’s check that this contract actually exists on a public blockchain. It’s very convenient to do so using the Open in Explorer link which opens Etherscan or PolygonScan depending on the network you chose.

image5-Mar-14-2024-12-53-43-7879-AM

Details of the deployed contract on PolygonScan

By navigating to the Contract tab, you can see the source code that powers your contract. The SCP, by default, verifies your contract in order to enable this functionality.

Notice that your contract is being powered by over 45 files containing thousands of lines of Solidity code! Understanding every component of this code is beyond this article—and even beyond the reach of many advanced Solidity developers. However, since we used SCP, we don’t have to worry about these details or auditing this code.

Step 3: Distributing rewards

Next let’s look at an example of how you can distribute your new points. To do that, we need to integrate our new contract into our application. Once integrated, we can call its functions to award points, burn points after spending, transfer points from one person to another, etc...

This is simple for contracts built using the SCP. Simply navigate to the ABI functions tab and you’ll see a list of functions you can invoke (both read and write).

image6-Mar-14-2024-12-53-43-5999-AM

And you don’t need to write the code to invoke these functions. SCP creates the snippets for you—in a wide variety of languages and libraries.

For instance, let’s say you have a React app. You’d like your user to be able to mint their points. This is made possible using the mintTo function and the following snippet created by SCP easily added to your app. In this snippet, we use the abiFunctionSignature to denote which function we intend on calling (in this case, mintTo). Also note, that we’re passing in the contract address and function parameters (or abiParameters) as part of the post data. The former allows SCP to find and execute the function on the current contract whereas the latter gives the function all the arguments it needs to execute correctly (in our case, the receiver address and the amount of tokens).

import axios from 'axios';const options = {  method: 'POST',  url: 'https://api.circle.com/v1/w3s/developer/transactions/contractExecution',  headers: {    Authorization: 'Bearer ${API_KEY}',    accept: 'application/json',    'content-type': 'application/json'  },  data: {    abiFunctionSignature: 'mintTo(address,uint256)',    idempotencyKey: '960a22f2-e666-4972-a5d1-b24bc7108bab',    abiParameters: ['0xC1F7Efe5B3f92c09298CE7845D05AF13EF448B4c', '250'],    contractAddress: '0x44dd2ee642f4f483357bd65a314b27fa9717c68c',    feeLevel: 'MEDIUM',    walletId: '${WALLET_ID}',    entitySecretCiphertext: '${ENTITY_SECRET_CIPHERTEXT}'  }};try {  const { data } = await axios.request(options);  console.log(data);} catch (error) {  console.error(error);}

Transferring tokens with the transfer function is similar to the mint function. We specify the function’s signature, the contract’s address, and the function’s arguments in the post data. Here, the parameter values denote that we are transferring 200 tokens to the address 0xCIF7.

import axios from 'axios';const options = {  method: 'POST',  url: 'https://api.circle.com/v1/w3s/developer/transactions/contractExecution',  headers: {    Authorization: 'Bearer ${API_KEY}',    accept: 'application/json',    'content-type': 'application/json'  },  data: {    abiFunctionSignature: 'transfer(address,uint256)',    abiParameters: ['0xC1F7Efe5B3f92c09298CE7845D05AF13EF448B4c', '200'],    idempotencyKey: '4b257758-88be-43d6-9883-01d2d504bd73',    contractAddress: '0x44dd2ee642f4f483357bd65a314b27fa9717c68c',    feeLevel: 'MEDIUM',    walletId: '${WALLET_ID}',    entitySecretCiphertext: '${ENTITY_SECRET_CIPHERTEXT}'  }};try {  const { data } = await axios.request(options);  console.log(data);} catch (error) {  console.error(error);}


You have access to a range of capabilities for points management, including creation, burning, balance retrieval, and transfers, among others.

Step 4: Redeeming rewards points

Finally, let’s look at how you might invoke your new points system to redeem points. Here is the code snippet created by SCP:

import axios from 'axios';const options = {  method: 'POST',  url: 'https://api.circle.com/v1/w3s/developer/transactions/contractExecution',  headers: {    Authorization: 'Bearer ${API_KEY}',    accept: 'application/json',    'content-type': 'application/json'  },  data: {    abiFunctionSignature: 'burnFrom(address,uint256)',    abiParameters: ['0xC1F7Efe5B3f92c09298CE7845D05AF13EF448B4c', '100'],    idempotencyKey: '3ca55d2b-b0ec-4876-9584-da44f8b5f756',    contractAddress: '0x44dd2ee642f4f483357bd65a314b27fa9717c68c',    feeLevel: 'MEDIUM',    walletId: '${WALLET_ID}',    entitySecretCiphertext: '${ENTITY_SECRET_CIPHERTEXT}'  }};try {  const { data } = await axios.request(options);  console.log(data);} catch (error) {  console.error(error);}


Redemption effectively means burning tokens and removing them from supply. Therefore, as the post data suggests, we execute the burnFrom function and specify the wallet address and token amount to burn (in this case, we’ve asked to burn 100 tokens from the same wallet as above).

Conclusion

Loyalty programs are an exciting use case for blockchain. They offer a powerful, secure, and cost-efficient platform for giving your users rewards. And with minimal blockchain knowledge and a high-level understanding of the ERC-20 standard, you can now use the SCP to create and launch your own blockchain-based loyalty program.

If you’re a team exploring how Web3 can transform your business through loyalty programs or other use cases, we encourage you to explore our quickstart guides to all our Web3 services and explore what Circle has to offer. We also encourage you to join our Discord community where you can meet like-minded teams building the next great thing on blockchain.

To get started with Smart Contract Platform, check out the documentation available here.

Sign up for an account to get started.

New call-to-action

*Programmable Wallets and Smart Contract Platform application programming interface (“API”) are offered by Circle Technology Services, LLC (“CTS”). CTS is not a regulated financial services company and the API does not include financial, investment, tax, legal, regulatory, accounting, business, or other advice. For additional details, please click here to see the Circle Developer terms of service.

Related posts

Web3 Services: November 2024 Updates

Web3 Services: November 2024 Updates

December 4, 2024
Monitoring your smart contract activity just got easier

Monitoring your smart contract activity just got easier

December 3, 2024
Circle Announces 3rd Cohort of USDC Grant Program Recipients

Circle Announces 3rd Cohort of USDC Grant Program Recipients

November 27, 2024
Blog
Leveraging Smart Contracts to Manage Loyalty Points
leveraging-smart-contracts-to-manage-loyalty-points
March 14, 2024
Leveraging smart contracts for blockchain loyalty programs can help foster innovative experiences and enable brands to expand their reach. Learn more.
Developer
Web3 Services
Programmable Wallets
Smart Contract Platform