1.2.6 β€’ Published 1 year ago

@linkdrop/sdk v1.2.6

Weekly downloads
3
License
MIT
Repository
-
Last release
1 year ago

Linkdrop SDK

It's either possible to generate links and campaigns using our Dashboard or using SDK:

Short description

SDK for computing proxy address, generating and claiming linkdrops

Installation

yarn add @linkdrop/sdk

Usage

const LinkdropSDK = require('@linkdrop/sdk')

// OR

import LinkdropSDK from '@linkdrop/sdk'

Initialization

const linkdropSDK = new LinkdropSDK({
  linkdropMasterAddress,
  factoryAddress,
  сhain = 'mainnet',
  jsonRpcUrl = `https://${chain}.infura.io`,
  apiHost = `https://${chain}.linkdrop.io`,
  claimHost = 'https://claim.linkdrop.io'
})

Linkdrop SDK constructor takes following params:

  • Required params:
    • linkdropMasterAddress - Linkdrop master address
    • factoryAddress - Linkdrop factory contract address

You can use the factory contract deployed on Mainnet, Ropsten, Rinkeby, Goerli and Kovan at 0xBa051891B752ecE3670671812486fe8dd34CC1c8

  • Optional params:
    • chain - Chain name, Currently supported chains are 'mainnet', 'ropsten', 'rinkeby', 'goerli' and 'kovan'. Will use 'mainnet' by default
    • jsonRpcUrl - JSON RPC URL to Ethereum node. Will use ${chain}.infura.io by default
    • apiHost - Linkdrop Relayer Service API host. Will use ${chain}.linkdrop.io by default
    • claimHost - Claiming page url host. Will use claim.linkdrop.io by default

With the SDK initialized you now need to take the following steps to distribute claimable linkdrops:

Precompute proxy address

let proxyAddress = linkdropSDK.getProxyAddress(campaignId = 0)

This function precomputes the proxy address for each campaign.

⚠️ If you are integrating one-to-one linkdrops you should always use campaignId = 0

Approve ERC20 tokens to proxy address

const txHash = await linkdropSDK.approve({ 
    signingKeyOrWallet,
    proxyAddress,
    tokenAddress,
    tokenAmount
})

This function will approve tokenAmount tokens to provided proxy address

Approve ERC721 tokens to proxy contract

const txHash = await linkdropSDK.approveERC721({ 
    signingKeyOrWallet,
    proxyAddress,
    nftAddress
})

This function will approve all NFTs to provided proxy address

Top-up proxy address with ETH

const txHash = await linkdropSDK.topup({ 
    signingKeyOrWallet,
    proxyAddress,
    weiAmount 
})

This function will topup the provided proxy address with weiAmount ethers

Top-up and deploy proxy contract

const txHash = await linkdropSDK.deployProxy({ signingKeyOrWallet, campaignId = 0, weiAmount })

This function will deploy a proxy contract for a given campaign id and top it up with weiAmount provided

Generate links

Generate link for ETH or ERC20

const {
  url,
  linkId,
  linkKey,
  linkdropSignerSignature
} = await linkdropSDK.generateLink({
    signingKeyOrWallet, // Signing private key or ethers.js Wallet instance
    weiAmount, // Amount of wei per claim
    tokenAddress, // ERC20 token address
    tokenAmount, // Amount of ERC20 tokens per claim
    expirationTime = 12345678910, // Link expiration time
    campaignId = 0, // Campaign id
  })

This function will generate link for claiming ETH or any ERC20 token and return the following params url, linkId, linkKey, linkdropSignerSignature

Generate link for ERC721

const {
  url,
  linkId,
  linkKey,
  linkdropSignerSignature
} = await linkdropSDK.generateLinkERC721({
    signingKeyOrWallet, // Signing private key or ethers.js Wallet instance
    weiAmount, // Amount of wei per claim
    nftAddress, // ERC721 token address
    tokenId, // Token id
    expirationTime = 12345678910, // Link expiration time
    campaignId = 0, // Campaign id
  })

This function will generate link for claiming ERC721 token and return the following params url, linkId, linkKey, linkdropSignerSignature

Claim links

Claim ETH or ERC20

const txHash = await linkdropSDK.claim({
    weiAmount, // Amount of wei per claim
    tokenAddress, // ERC20 token address
    tokenAmount, // Amount of ERC20 tokens to claim
    expirationTime = 12345678910, // Link expiration time
    linkKey, // Link ephemeral key
    linkdropSignerSignature, // Signature of linkdrop signer
    receiverAddress, // Address of receiver
    campaignId = 0, // Campaign id
}

This function will claim ETH or ERC20 token by making a POST request to server endpoint. Make sure the server is up by running yarn server.

Claim ERC721

const txHash = await linkdropSDK.claim({
    weiAmount, // Amount of wei per claim
    nftAddress, // ERC721 token address
    tokenId, // Token id to claim
    expirationTime = 12345678910, // Link expiration time
    linkKey, // Link ephemeral key
    linkdropSignerSignature, // Signature of linkdrop signer
    receiverAddress, // Address of receiver
    campaignId = 0, // Campaign id
}

This function will claim ETH or ERC20 token by making a POST request to server endpoint. Make sure the server is up by running yarn server.

Subscribe for Claimed events

await linkdropSDK.subscribeForClaimedEvents(proxyAddress, callback)

Subscribe for ClaimedERC721 events

await linkdropSDK.subscribeForClaimedERC721Events(proxyAddress, callback)

Stay in Touch

  • πŸ’¬ Join Linkdrop Community in Telegram to chat with the core team
  • πŸ•Ή Try out Linkdrop Dashboard to generate onboarding links
  • πŸ™Œ Want to contribute to the project β€” just ping us
  • πŸ’Œ Reach us at hi@linkdop.io
1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

2.1.9-alpha.0

4 years ago

2.1.8-alpha.0

4 years ago

2.1.7-alpha.0

4 years ago

2.1.5-alpha.0

4 years ago

2.1.6-alpha.0

4 years ago

2.1.4-alpha.0

4 years ago

2.1.3-alpha.0

4 years ago

2.1.1-alpha.0

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

2.1.0-alpha.0

4 years ago

2.0.18-alpha.0

4 years ago

2.0.17-alpha.0

4 years ago

2.0.16-alpha.0

4 years ago

2.0.15-alpha.0

4 years ago

2.0.14-alpha.0

4 years ago

2.0.13-alpha.0

4 years ago

2.0.12-alpha.0

4 years ago

2.0.11-alpha.0

4 years ago

2.0.9-alpha.0

4 years ago

2.0.10-alpha.0

4 years ago

2.0.8-alpha.0

4 years ago

2.0.7-alpha.0

4 years ago

2.0.6-alpha.0

4 years ago

2.0.5-alpha.0

4 years ago

2.0.3-alpha.0

4 years ago

2.0.2-alpha.0

4 years ago

2.0.1-alpha.0

4 years ago

2.0.0-alpha.0

4 years ago

1.0.88

5 years ago

1.0.87

5 years ago

1.0.86

5 years ago

1.0.85

5 years ago

1.0.83

5 years ago

1.0.75

5 years ago

1.0.74

5 years ago

1.0.73

5 years ago

1.0.72

5 years ago

1.0.71

5 years ago

1.0.70

5 years ago

1.0.48

5 years ago

1.0.47

5 years ago

1.0.46

5 years ago

1.0.45

5 years ago

1.0.44

5 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago