# @linkdrop/sdk

> It's either possible to generate links and campaigns using our [Dashboard](https://dashboard.linkdrop.io) or using SDK:

Latest version **1.2.6** (published 2022-11-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @linkdrop/sdk
pnpm add @linkdrop/sdk
yarn add @linkdrop/sdk
bun add @linkdrop/sdk
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2022-11-30 |
| First published | 2019-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 178.6 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | bigmacxhaz, dobrokhvalov, spacehaz |

## Links

- npm: https://www.npmjs.com/package/@linkdrop/sdk
- npm.io page: https://npm.io/package/@linkdrop/sdk

## Dependencies (6)

- [axios](https://npm.io/package/axios.md) 0.27.2
- [ethers](https://npm.io/package/ethers.md) ^4.0.27
- [uint8arrays](https://npm.io/package/uint8arrays.md) 3.1.0
- [@stablelib/x25519](https://npm.io/package/@stablelib/x25519.md) 1.0.2
- [ethereumjs-wallet](https://npm.io/package/ethereumjs-wallet.md) ^0.6.3
- [@linkdrop/contracts](https://npm.io/package/@linkdrop/contracts.md) ^1.2.6

## Recent versions

- 1.2.6 (latest) — 2022-11-30
- 2.1.9-alpha.0 (react-native) — 2020-06-04
- 2.1.7-alpha.0 (next) — 2020-06-04
- 1.2.5 — 2022-11-11
- 1.2.4 — 2022-10-25
- 1.2.3 — 2022-10-25
- 1.2.2 — 2022-10-25
- 1.2.1 — 2022-10-12
- 1.2.0 — 2021-12-20
- 1.1.6 — 2020-08-12
- 1.1.5 — 2020-08-12
- 1.1.4 — 2020-07-27
- 1.1.3 — 2020-07-27
- 2.1.8-alpha.0 — 2020-06-04
- 2.1.6-alpha.0 — 2020-06-04
- … 74 more at https://npm.io/package/@linkdrop/sdk/versions

## README

# Linkdrop SDK

It's either possible to generate links and campaigns using our [Dashboard](https://dashboard.linkdrop.io) or using SDK:

## Short description

SDK for computing proxy address, generating and claiming linkdrops

## Installation

```bash
yarn add @linkdrop/sdk
```

## Usage

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

// OR

import LinkdropSDK from '@linkdrop/sdk'
```

## Initialization

```js
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

```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`


### Approve ERC20 tokens to proxy address

```js
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

```js
const txHash = await linkdropSDK.approveERC721({ 
    signingKeyOrWallet,
    proxyAddress,
    nftAddress
})
```
This function will approve all NFTs to provided proxy address

### Top-up proxy address with ETH

```js
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

```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

## Generate links

### Generate link for ETH or ERC20

```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`

### Generate link for ERC721

```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`

## Claim links

### Claim ETH or ERC20

```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`.

### Claim ERC721

```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`.

### Subscribe for `Claimed` events

```js
await linkdropSDK.subscribeForClaimedEvents(proxyAddress, callback)
```

### Subscribe for `ClaimedERC721` events

```js
await linkdropSDK.subscribeForClaimedERC721Events(proxyAddress, callback)
```

## Stay in Touch
- 💬 Join [Linkdrop Community](https://t.me/linkdrophq) in Telegram to chat with the core team
- 🕹 Try out [Linkdrop Dashboard](https://dashboard.linkdrop.io) to generate onboarding links
- 🙌 Want to contribute to the project — just ping us
- 💌 Reach us at hi@linkdop.io

---
_Source: https://npm.io/package/@linkdrop/sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
