It's either possible to generate links and campaigns using our [Dashboard](https://dashboard.linkdrop.io) or using SDK:
It's either possible to generate links and campaigns using our Dashboard or using SDK:
SDK for computing proxy address, generating and claiming linkdrops
``bash`
yarn add @linkdrop/sdk
`js
const LinkdropSDK = require('@linkdrop/sdk')
// OR
import LinkdropSDK from '@linkdrop/sdk'
`
`jshttps://${chain}.infura.io
const linkdropSDK = new LinkdropSDK({
linkdropMasterAddress,
factoryAddress,
Ρhain = 'mainnet',
jsonRpcUrl = ,https://${chain}.linkdrop.io
apiHost = ,`
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${chain}.linkdrop.io
- apiHost - Linkdrop Relayer Service API host. Will use by defaultclaim.linkdrop.io
- claimHost - Claiming page url host. Will use by default
With the SDK initialized you now need to take the following steps to distribute claimable linkdrops:
`js`
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
`js`
const txHash = await linkdropSDK.approve({
signingKeyOrWallet,
proxyAddress,
tokenAddress,
tokenAmount
})tokenAmount
This function will approve tokens to provided proxy address
`js`
const txHash = await linkdropSDK.approveERC721({
signingKeyOrWallet,
proxyAddress,
nftAddress
})
This function will approve all NFTs to provided proxy address
`js`
const txHash = await linkdropSDK.topup({
signingKeyOrWallet,
proxyAddress,
weiAmount
})weiAmount
This function will topup the provided proxy address with ethers
`js`
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
`js`
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
`js`
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
`js`
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.
`js`
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.
`js`
await linkdropSDK.subscribeForClaimedEvents(proxyAddress, callback)
`js``
await linkdropSDK.subscribeForClaimedERC721Events(proxyAddress, callback)