Create & manage campaigns

IMPORTANT! FOR BACK-END USE ONLY! Managing campaigns requires secret keys that should never be exposed to public. Use campaign methods on a back-end and never within a front-end app.

Basic concepts

There are few basic concepts that you should be aware to generate claim links with Linkdrop SDK

Links are stored in batches, which are themselves a part of the campaigns. Campaign can have several batches, and you can also add more links into different batches within the campaign.

  1. You should first create a campaign using Dashboard, see Keys and installation, and save your campaignId, signerKey and encryptionKey

  2. Get a campaign by using campaignId, signerKey and encryptionKey

  3. Create a new batch. You will also see in the Dashboard and be able to download links in CSV there

  4. Use batch.addLinks to add more links to a batch

Managing Campaigns

IMPORTANT! FOR BACK-END USE ONLY! Managing campaigns requires secret keys that should never be exposed to public. Use campaign methods on a back-end and never within a front-end app.

After you have created a campaign using Linkdrop Dashboard, you can use SDK to manage the campaign. Using SDK you can:

  • fetch campaign data

  • create a new batch of claim links

  • add claim links to an existing batch

  • fetch created claim links

  • activate or deactivate links

Getting Campaign

To be able to do all that, first you need to fetch initialize campaign object

const campaign = await sdk.getCampaign(
  campaignId: string,
  signerKey: string,
  encryptionKey: string
)

Get all params from the campaign page on Dashboard:

  • campaignId: ID of the campaign that you want to retrieve information about.

  • signerKey: private key used to create claim links. (NEVER EXPOSE SIGNER KEY PUBLICLY)

  • encryptionKey: private key used to encode and decode sensitive data stored on server (NEVER EXPOSE ENCRYPTION KEY PUBLICLY)

IMPORTANT! FOR BACK-END USE ONLY! Managing campaigns requires secret keys that should never be exposed to public. Use campaign methods on a back-end and never within a front-end app.

The returned campaign object has campaign data and addtional methods to manage the campaign.

console.log(campaign.data)

Creating new batch

To create a batch of claim links for the campaign, use the campaign.createBatch method

const batch = await campaign.createBatch(
  [{ 
    id: string,
    amount: string,
    links: string,
    weiAmount?: string // optional parameter, The default value is `0`.
  }],
  // optional parameters
  {
    batchDescription: string,
    shortCodeLength: number,
    shortCodeMixRegister: boolean,
    expirationTime: string
  }
)

It takes two parameters:

  • linkData: This is a required array of objects that contain information about the links to be created. Each object in the array must have the following properties:

    • id: token ID for ERC721/ERC1155 campaigns. For ERC20 campaigns, id is not provided.

    • amount: amount of tokens per link for ERC20/ERC1155 campaigns. For ERC721 campaigns, amount is not provided.

    • links: number of links to create.

    • weiAmount: amount of network tokens (ETH/MATIC) to be sent to receiver on claim. Campaign contract should have enough network tokens before claim. Top up the campaign contract in advance manually. The default value is 0.

  • options: This is an optional object that can contain the following properties:

    • batchDescription: This is an optional string property that specifies the description of the batch. The default value is "Created by SDK".

    • shortCodeLength: The length of claimCode. The default value is 12.

    • shortCodeMixRegister: Should the claim code contain uppercase and lowercase symbols. The default value is true.

    • expirationTime: Timestamp for the link expiration date. The default value is 1900000000000.

The returned batch object contains information related to the specified batch and methods to manage it.

Getting Batches

To retrieve all batches associated with the campaign, call the campaign.getBatches method:

const batches = await campaign.getBatches()

Getting Batch

To manage a batch, first you need to retrieve it by ID:

const batch = await campaign.getBatch(
  batchId: string
) 

The returned batch object contains information related to the specified batch and methods to manage it.

Batch methods

Adding Links to an existing batch

To add claim links to an existing batch, call the batch.addLinks method:

const links = await batch.addLinks(
  [{ 
    id: string, 
    amount: string, 
    links: string, 
    weiAmount: string // optional parameter, The default value is `0`.
  }], {
    // optional parameters
    shortCodeLength: number,
    shortCodeMixRegister: boolean,
    expirationTime: string
  }
) 

It takes two parameters and returns an array of link IDs:

  1. links: An array of link objects that contain the following properties:

  • id: The token ID (required for ERC721/ERC1155 campaigns).

  • amount: The amount of tokens per link (required for ERC20/ERC1155 campaigns).

  • links: The number of links to be created.

  • weiAmount: The amount of native tokens that should be sent to the proxy contract address manually. The default value is 0.

  1. options: This is an optional object that can contain the following properties:

  • shortCodeLength: The length of claimCode. The default value is 12.

  • shortCodeMixRegister: Should the claim code contain uppercase and lowercase symbols. The default value is true.

  • expirationTime: Timestamp for the link expiration date. The default value is 1900000000000.

Getting Links

To fetch all links created for that batch, use the batch.getLinks method:

const links = await batch.getLinks()

Individual link deactivation is only available when using the SDK. If the user will follow the link that has been deactivated, he will see a corresponding message "Link deactivated"

Deactivate Link

To deactivate link:

const success = await campaign.deactivate(
  claimCode: string
)

Parameters:

  • claimCode: The claimCode parameter from the claim link URL.

Reactivate Link

To reactivatate previosly deactivated link:

const success = await campaign.reactivate(
  claimCode: string
) 

Parameters:

  1. claimCode: The claimCode parameter from the claim link URL.

Last updated