Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
spacehaz committed Nov 20, 2024
1 parent 6103794 commit d4878aa
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Linkdrop SDK

## 2.0.10
-
- apiKey added

## 2.0.9
- added src param to link (src=d)
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Linkdrop SDK
# Linkdrop Batch SDK

Linkdrop provides tools to distribute NFTs with links, QR codes or claim codes. The Linkdrop SDK is a Typescript library that can be used to automate creating and managing claim links.

Expand All @@ -24,19 +24,21 @@ Create a campaign using Linkdrop Dashboard. When creating a campaign you will ne

First, import SDK into your code:
```ts
import LinkdropSDK from 'linkdrop-sdk'
import LinkdropBatchSDK from 'linkdrop-sdk'
// or
// const LinkdropSDK = require('linkdrop-sdk').default
```
To use SDK on a tesnet:
```ts
const apiKey = /* to request an API key, please contact us at [email protected] */
// initializing Linkdrop SDK on a testnet (Goerli or Mumbai)
const sdk = new LinkdropSDK({ mode: 'testnets' });
const sdk = new LinkdropBatchSDK({ mode: 'testnets', apiKey });
```
To use SDK on a production network (Ethereum Mainnet or Polygon):
```ts
const apiKey = /* to request an API key, please contact us at [email protected] */
// initializing Linkdrop SDK on a production network
const sdk = new LinkdropSDK();
const sdk = new LinkdropBatchSDK({ apiKey });
```

## Claim methods (Can be used on Front-end & Back-end)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "linkdrop-sdk",
"name": "linkdrop-batch-sdk",
"version": "2.0.10",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -12,18 +12,18 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/LinkdropHQ/linkdrop-sdk.git"
"url": "git+https://github.com/LinkdropHQ/linkdrop-batch-sdk.git"
},
"author": "spacehaz <[email protected]>",
"license": "MIT",
"description": "",
"bugs": {
"url": "https://github.com/LinkdropHQ/linkdrop-sdk/issues"
"url": "https://github.com/LinkdropHQ/linkdrop-batch-sdk/issues"
},
"engines": {
"node": ">=16.x"
},
"homepage": "https://github.com/LinkdropHQ/linkdrop-sdk#readme",
"homepage": "https://github.com/LinkdropHQ/linkdrop-batch-sdk#readme",
"keywords": [],
"dependencies": {
"@stablelib/x25519": "^1.0.3",
Expand Down
6 changes: 3 additions & 3 deletions src/api/link/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const requests: TRequests = {
) => {
const headers = defineRequestKeyHeader(apiKey)

return axios.get(`${apiHost}/api/v2/claim-links/${linkId}`)
return axios.get(`${apiHost}/api/v2/claim-links/${linkId}`, { headers })
},
getStatus: (
apiHost,
Expand All @@ -19,7 +19,7 @@ const requests: TRequests = {
) => {
const headers = defineRequestKeyHeader(apiKey)

return axios.get(`${apiHost}/api/v2/claim-links/${linkId}/status`)
return axios.get(`${apiHost}/api/v2/claim-links/${linkId}/status`, { headers })
},
deactivateLink: (
apiHost,
Expand Down Expand Up @@ -54,7 +54,7 @@ const requests: TRequests = {
return axios.post(`${apiHost}/api/v2/claim-links/${linkId}/claim`, {
receiver_address: receiverAddress,
receiver_signature: receiverSignature
})
}, { headers })
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/redeem-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { signReceiverAddress } from '../utils'
const redeemLink = async (
code: string,
receiverAddress: string,
apiHost: string
apiHost: string,
apiKey: string
) => {
const linkKey = ethers.utils.id(code)
const wallet = new ethers.Wallet(linkKey)
const receiverSignature = await signReceiverAddress(wallet, receiverAddress)
const claimLink = await linkApi.redeemLink(
apiHost,
apiKey,
wallet.address,
receiverAddress,
receiverSignature
Expand Down
6 changes: 5 additions & 1 deletion src/modules/batch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Batch implements IBatch {
claimHostUrl: string
campaignData: TCampaignItem
signerKey: string
apiKey: string

constructor (
batchId: string,
Expand All @@ -25,7 +26,8 @@ class Batch implements IBatch {
campaignData: TCampaignItem,
signerKey: string,
campaignSig: string,
apiHost: string
apiHost: string,
apiKey: string
) {
this.batchId = batchId
this.data = data
Expand All @@ -36,6 +38,7 @@ class Batch implements IBatch {
this.claimHostUrl = claimHostUrl
this.campaignData = campaignData
this.signerKey = signerKey
this.apiKey = apiKey
}

addLinks: TAddLinks = async (
Expand Down Expand Up @@ -66,6 +69,7 @@ class Batch implements IBatch {
if (!transformedAssets) { return alert('Error with assets') }
return await batchesApi.addLinks(
this.apiHost,
this.apiKey,
this.campaignSig,
this.campaignData.campaign_id,
this.batchId,
Expand Down
14 changes: 12 additions & 2 deletions src/modules/campaign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Campaign implements ICampaign {
apiHost: string
claimHostUrl: string
campaignSig: string
apiKey: string

constructor (
campaignId: string,
Expand All @@ -27,8 +28,11 @@ class Campaign implements ICampaign {
data: TCampaignItem,
claimHostUrl: string,
campaignSig: string,
apiHost: string
apiHost: string,
apiKey: string

) {
this.apiKey = apiKey
this.campaignId = campaignId
this.signerKey = signerKey
this.encryptionKey = encryptionKey
Expand All @@ -41,6 +45,7 @@ class Campaign implements ICampaign {
getBatches: TGetBatches = async () => {
const campaignData = await batchesApi.getBatches(
this.apiHost,
this.apiKey,
this.campaignSig,
this.campaignId
)
Expand All @@ -59,6 +64,7 @@ class Campaign implements ICampaign {
) => {
const campaignData = await batchesApi.getBatch(
this.apiHost,
this.apiKey,
this.campaignSig,
this.campaignId,
batchId
Expand All @@ -75,7 +81,8 @@ class Campaign implements ICampaign {
this.data,
this.signerKey,
this.campaignSig,
this.apiHost
this.apiHost,
this.apiKey
)
}
}
Expand Down Expand Up @@ -110,6 +117,7 @@ class Campaign implements ICampaign {
if (!transformedAssets) { return alert('Error with assets') }
const response = await batchesApi.createBatch(
this.apiHost,
this.apiKey,
this.campaignSig,
this.data.campaign_id,
transformedAssets,
Expand Down Expand Up @@ -139,6 +147,7 @@ class Campaign implements ICampaign {

const linkData = await linkApi.reactivateLink(
this.apiHost,
this.apiKey,
this.campaignSig,
wallet.address
)
Expand All @@ -157,6 +166,7 @@ class Campaign implements ICampaign {

const linkData = await linkApi.deactivateLink(
this.apiHost,
this.apiKey,
this.campaignSig,
wallet.address
)
Expand Down
20 changes: 17 additions & 3 deletions src/modules/linkdrop-sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class LinkdropSDK implements ILinkdropSDK {
chain: TNetworkName
apiHost: string
claimHostUrl: string
apiKey: string

utils = {
createLink,
computeProxyAddress,
Expand All @@ -23,13 +25,20 @@ class LinkdropSDK implements ILinkdropSDK {
constructor ({
apiHost,
mode,
claimHostUrl
claimHostUrl,
apiKey
}: {
apiKey?: string,
apiHost?: string,
mode?: 'testnets',
claimHostUrl?: string
} = {}) {
this.claimHostUrl = claimHostUrl || ''
if (!apiKey) {
throw new Error('ApiKey required')
} else {
this.apiKey = apiKey
}
if (apiHost) {
this.apiHost = apiHost
} else {
Expand Down Expand Up @@ -58,6 +67,7 @@ class LinkdropSDK implements ILinkdropSDK {
)
const campaignData = await campaignsApi.getCampaign(
this.apiHost,
this.apiKey,
campaignSig,
campaignId
)
Expand All @@ -71,7 +81,8 @@ class LinkdropSDK implements ILinkdropSDK {
campaign,
this.claimHostUrl,
campaignSig,
this.apiHost
this.apiHost,
this.apiKey
)
}
}
Expand All @@ -82,7 +93,8 @@ class LinkdropSDK implements ILinkdropSDK {
const result = await redeemLink(
claimCode,
destination,
this.apiHost
this.apiHost,
this.apiKey,
)
if (!result) {
throw new Error('Link claim failed')
Expand All @@ -98,6 +110,7 @@ class LinkdropSDK implements ILinkdropSDK {
) {
return await getLinkParams(
this.apiHost,
this.apiKey,
claimCode
)
}
Expand All @@ -107,6 +120,7 @@ class LinkdropSDK implements ILinkdropSDK {
) {
const result = await getLinkStatus(
this.apiHost,
this.apiKey,
claimCode
)
if (!result) {
Expand Down

0 comments on commit d4878aa

Please sign in to comment.