Managing affiliate codes using the Fuul SDK

This article shows how to create, edit, and get affiliate codes with the 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: "0x123485090123"
});

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:

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-affiliate-code",
  signature: "0x123485090123"
});

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

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