🔗Creating affiliate links or codes

To create tracking links use the generateTrackingLink method. This generates a tracking link for the affiliate to share your program link.

import { Fuul } from ('@fuul/sdk');

const trackingLinkUrl = await Fuul.generateTrackingLink(
    baseURL, affiliateAddress)

// Returns
"http://yourwebsite.com?af=<affiliateAddressOrCode>"

baseURL: the URL of your website (where the pageview and connect wallet events are implemented)

affiliateAddress: the address of the affiliate. Usually, it is the one that is connected to the site.

You can find an example of two landing pages (one for creators and another one for end users) with the Fuul SDK integrated using next JS and RainbowKit in this repo

Managing affiliate codes using Fuul SDK

By default, affiliate links have the af=affiliateAddress parameter to identify the affiliate that referred the click.

Fuul allows affiliates to create their own codes to hide their addresses and make prettier links.

Check out the following example to get a better idea.

// Without an affiliate code
"http://yourwebsite.com?af=0x1f9090aae28b8a3dceadf281b0f12828e676c326"

// With an affiliate code
"http://yourwebsite.com?af=my-affiliate-code"

Creating affiliate codes

Affiliates can create their codes on the Fuul Hosted solution, but projects can also choose to add the functionality to their website.

To create codes using the SDK, use the createAffiliateCode method.

import { Fuul } from ('@fuul/sdk');

await Fuul.createAffiliateCode({
  address: '0x12345',
  code: 'my-affiliate-code',
  signature: '0x12345',
  accountChainId: '1' // Only for smart contract wallets
})

address: the address of the affiliate. Usually, it is the one that is connected to the site.

code: the affiliate code to be created.

signature: the resulting signature of the address signing the following formatted message:

accountChainId: the chain id of the smart contract wallet. Do not include it when the wallet is an EOA.

I confirm that I am creating the ${{affiliateCode}} code on Fuul

E.g. I confirm that I am creating the my-affiliate-code code on Fuul

Return values

The method either succeeds and the code is registered or it throws one of the following errors:

ValidationError: The affiliate code has an invalid character. Codes can only be alphanumeric separated by dashes (-). E.g. my-affiliate-code

InvalidSignatureError: The signature is not valid for the address and message

AddressInUseError: The address has already created an affiliate code

CodeInUseError: The code has already been taken by another user

Updating affiliate codes

To update an affiliate code, use the updateAffiliateCode method.

import { Fuul } from ('@fuul/sdk');

await Fuul.updateAffiliateCode({
  address: '0x12345',
  code: 'my-new-cool-code',
  signature: '0x123455',
  accountChainId: '1' // Only for smart contract wallets
})

address: the address of the affiliate. Usually, it is the one that is connected to the site

code: the new affiliate code

signature: the resulting signature of the address signing the following formatted message:

I confirm that I am updating my code to ${{affiliateCode}} on Fuul

E.g. I confirm that I am updating my code to my-affiliate-code on Fuul

accountChainId: the chain id of the smart contract wallet. Do not include it when the wallet is an EOA.

Return values

The method either succeeds and the code is registered or it throws one of the following errors:

ValidationError: The affiliate code has an invalid character. Codes can only be alphanumeric separated by dashes (-). E.g. my-affiliate-code

InvalidSignatureError: The signature is not valid for the address and message

CodeInUseError: The code has already been taken by another user

Getting the affiliate code registered to an address

To get the affiliate code for a specific address using the SDK, use thegetAffiliateCode method.

import { Fuul } from ('@fuul/sdk');

const affiliateCode = await Fuul.getAffiliateCode(
    '0x2d60a6F7Ce0ff573DD2A016DAb917C47Ffe1bA09')
    
// my-code

The return value will be either the code or null in case there is no code created for the input address.

Checking if an affiliate code is free to use

To check whether an affiliate code is free to use or taken using the SDK, use the isAffiliateCodeFree method.

import { Fuul } from ('@fuul/sdk');

const codeIsFree = await Fuul.isAffiliateCodeFree('my-code')

// True or false

The return value will be True if the code is free to use or False if it is already taken.

Last updated