@niftykit/redeemable 0.0.2 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/dist/cjs/{src/Redeemable.js → Redeemable.js} +61 -17
- package/dist/cjs/config/endpoint.js +5 -0
- package/dist/cjs/{src/index.js → index.js} +0 -0
- package/dist/cjs/types/api-responses.js +2 -0
- package/dist/esm/{src/Redeemable.js → Redeemable.js} +59 -18
- package/dist/esm/config/endpoint.js +2 -0
- package/dist/esm/{src/index.js → index.js} +0 -0
- package/dist/esm/types/api-responses.js +1 -0
- package/dist/types/{src/Redeemable.d.ts → Redeemable.d.ts} +9 -5
- package/dist/types/config/endpoint.d.ts +2 -0
- package/dist/types/{src/index.d.ts → index.d.ts} +0 -0
- package/dist/types/types/api-responses.d.ts +6 -0
- package/dist/umd/index.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Redeemable SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
NiftyKit Redeemable SDK Library.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Install via npm or yarn
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
# with npm
|
|
@@ -14,7 +14,7 @@ npm install @niftykit/redeemable
|
|
|
14
14
|
yarn add @niftykit/redeemable
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Or use it via CDN
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
20
|
<script async src='https://unpkg.com/@niftykit/redeemable/dist/umd/index.js'></script>
|
|
@@ -30,13 +30,18 @@ Example URL:
|
|
|
30
30
|
https://app.niftykit.com/collections/your-collection/redeemables/1/0x5f635ae4051272d477a6ebbcdfd32d2d55a300004512c01873315194d853f15b29087799de88530240a0a0f17f5e9f8d6881b4b248ebc83c06ce7c33b9ef01971b
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
In this case the `tokenId` is `1` and the signature is
|
|
33
|
+
In this case the `tokenId` is `1` and the signature is
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
0x5f635ae4051272d477a6ebbcdfd32d2d55a300004512c01873315194d853f15b29087799de88530240a0a0f17f5e9f8d6881b4b248ebc83c06ce7c33b9ef01971b
|
|
37
|
+
```
|
|
34
38
|
|
|
35
39
|
> Note: if you re-generate your redeemable link, you will get a new `signature` and need to update your code.
|
|
36
40
|
|
|
37
41
|
```typescript
|
|
38
42
|
// using ethers.js
|
|
39
43
|
import { ethers } from 'ethers';
|
|
44
|
+
import Redeemable from '@niftykit/redeemable';
|
|
40
45
|
|
|
41
46
|
const provider = new ethers.providers.Web3Provider(window.ethereum, 'any');
|
|
42
47
|
await provider.send('eth_requestAccounts', []);
|
|
@@ -35,30 +35,65 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
38
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
42
|
var typechain_1 = require("@niftykit/contracts/typechain");
|
|
43
|
+
var axios_1 = __importDefault(require("axios"));
|
|
44
|
+
var ethers_1 = require("ethers");
|
|
45
|
+
var endpoint_1 = require("./config/endpoint");
|
|
40
46
|
var Redeemable = /** @class */ (function () {
|
|
41
|
-
function Redeemable() {
|
|
47
|
+
function Redeemable(isDev) {
|
|
42
48
|
this.contract = {};
|
|
49
|
+
this.version = 1;
|
|
50
|
+
this.isDev = isDev;
|
|
43
51
|
}
|
|
52
|
+
Object.defineProperty(Redeemable.prototype, "apiBaseUrl", {
|
|
53
|
+
get: function () {
|
|
54
|
+
return this.isDev ? endpoint_1.API_ENDPOINT_DEV : endpoint_1.API_ENDPOINT;
|
|
55
|
+
},
|
|
56
|
+
enumerable: false,
|
|
57
|
+
configurable: true
|
|
58
|
+
});
|
|
44
59
|
Redeemable.prototype.init = function (signerOrProvider, contractAddress) {
|
|
45
60
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var url, resp;
|
|
46
62
|
return __generator(this, function (_a) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
if (!ethers_1.ethers.utils.isAddress(contractAddress)) {
|
|
66
|
+
throw new Error('Invalid contract address.');
|
|
67
|
+
}
|
|
68
|
+
url = "".concat(this.apiBaseUrl, "/v2/redeemables/").concat(contractAddress);
|
|
69
|
+
return [4 /*yield*/, axios_1.default.get(url, {
|
|
70
|
+
validateStatus: function (status) { return status < 500; },
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
resp = _a.sent();
|
|
74
|
+
if (resp.status !== 200) {
|
|
75
|
+
throw new Error('Something went wrong.');
|
|
76
|
+
}
|
|
77
|
+
this.version = resp.data.version;
|
|
78
|
+
this.contract =
|
|
79
|
+
this.version === 1
|
|
80
|
+
? typechain_1.TokenCollection__factory.connect(contractAddress, signerOrProvider)
|
|
81
|
+
: typechain_1.TokenCollection__factoryV2.connect(contractAddress, signerOrProvider);
|
|
82
|
+
if (!this.contract) {
|
|
83
|
+
throw new Error('Initialization failed.');
|
|
84
|
+
}
|
|
85
|
+
return [2 /*return*/];
|
|
50
86
|
}
|
|
51
|
-
return [2 /*return*/];
|
|
52
87
|
});
|
|
53
88
|
});
|
|
54
89
|
};
|
|
55
|
-
Redeemable.create = function (signerOrProvider, contractAddress) {
|
|
90
|
+
Redeemable.create = function (signerOrProvider, contractAddress, isDev) {
|
|
56
91
|
return __awaiter(this, void 0, void 0, function () {
|
|
57
92
|
var instance;
|
|
58
93
|
return __generator(this, function (_a) {
|
|
59
94
|
switch (_a.label) {
|
|
60
95
|
case 0:
|
|
61
|
-
instance = new Redeemable();
|
|
96
|
+
instance = new Redeemable(isDev);
|
|
62
97
|
return [4 /*yield*/, instance.init(signerOrProvider, contractAddress)];
|
|
63
98
|
case 1:
|
|
64
99
|
_a.sent();
|
|
@@ -67,19 +102,28 @@ var Redeemable = /** @class */ (function () {
|
|
|
67
102
|
});
|
|
68
103
|
});
|
|
69
104
|
};
|
|
70
|
-
Redeemable.prototype.
|
|
105
|
+
Redeemable.prototype.getRedeemable = function (tokenId) {
|
|
71
106
|
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var payload;
|
|
73
|
-
return __generator(this, function (
|
|
74
|
-
switch (
|
|
75
|
-
case 0:
|
|
107
|
+
var payload, _a;
|
|
108
|
+
return __generator(this, function (_b) {
|
|
109
|
+
switch (_b.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
if (!(this.version === 1)) return [3 /*break*/, 2];
|
|
112
|
+
return [4 /*yield*/, this.contract.redeemableByIndex(tokenId)];
|
|
76
113
|
case 1:
|
|
77
|
-
|
|
114
|
+
_a = _b.sent();
|
|
115
|
+
return [3 /*break*/, 4];
|
|
116
|
+
case 2: return [4 /*yield*/, this.contract.redeemableAt(tokenId)];
|
|
117
|
+
case 3:
|
|
118
|
+
_a = _b.sent();
|
|
119
|
+
_b.label = 4;
|
|
120
|
+
case 4:
|
|
121
|
+
payload = _a;
|
|
78
122
|
return [2 /*return*/, {
|
|
79
123
|
index: tokenId,
|
|
80
|
-
tokenURI: payload
|
|
124
|
+
tokenURI: payload[0],
|
|
81
125
|
price: payload.price,
|
|
82
|
-
maxAmount: payload.
|
|
126
|
+
maxAmount: payload[3].toNumber(),
|
|
83
127
|
maxPerWallet: payload.maxPerWallet.toNumber(),
|
|
84
128
|
maxPerMint: payload.maxPerMint.toNumber(),
|
|
85
129
|
redeemedCount: payload.redeemedCount.toNumber(),
|
|
@@ -96,7 +140,7 @@ var Redeemable = /** @class */ (function () {
|
|
|
96
140
|
var nft;
|
|
97
141
|
return __generator(this, function (_a) {
|
|
98
142
|
switch (_a.label) {
|
|
99
|
-
case 0: return [4 /*yield*/, this.
|
|
143
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
100
144
|
case 1:
|
|
101
145
|
nft = _a.sent();
|
|
102
146
|
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes)'](nft.index, quantity, signature, {
|
|
@@ -112,7 +156,7 @@ var Redeemable = /** @class */ (function () {
|
|
|
112
156
|
var nft;
|
|
113
157
|
return __generator(this, function (_a) {
|
|
114
158
|
switch (_a.label) {
|
|
115
|
-
case 0: return [4 /*yield*/, this.
|
|
159
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
116
160
|
case 1:
|
|
117
161
|
nft = _a.sent();
|
|
118
162
|
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes,bytes32[])'](nft.index, quantity, signature, proof, {
|
|
File without changes
|
|
@@ -34,29 +34,61 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import { TokenCollection__factory, } from '@niftykit/contracts/typechain';
|
|
37
|
+
import { TokenCollection__factoryV2, TokenCollection__factory, } from '@niftykit/contracts/typechain';
|
|
38
|
+
import axios from 'axios';
|
|
39
|
+
import { ethers } from 'ethers';
|
|
40
|
+
import { API_ENDPOINT, API_ENDPOINT_DEV } from './config/endpoint';
|
|
38
41
|
var Redeemable = /** @class */ (function () {
|
|
39
|
-
function Redeemable() {
|
|
42
|
+
function Redeemable(isDev) {
|
|
40
43
|
this.contract = {};
|
|
44
|
+
this.version = 1;
|
|
45
|
+
this.isDev = isDev;
|
|
41
46
|
}
|
|
47
|
+
Object.defineProperty(Redeemable.prototype, "apiBaseUrl", {
|
|
48
|
+
get: function () {
|
|
49
|
+
return this.isDev ? API_ENDPOINT_DEV : API_ENDPOINT;
|
|
50
|
+
},
|
|
51
|
+
enumerable: false,
|
|
52
|
+
configurable: true
|
|
53
|
+
});
|
|
42
54
|
Redeemable.prototype.init = function (signerOrProvider, contractAddress) {
|
|
43
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var url, resp;
|
|
44
57
|
return __generator(this, function (_a) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
if (!ethers.utils.isAddress(contractAddress)) {
|
|
61
|
+
throw new Error('Invalid contract address.');
|
|
62
|
+
}
|
|
63
|
+
url = "".concat(this.apiBaseUrl, "/v2/redeemables/").concat(contractAddress);
|
|
64
|
+
return [4 /*yield*/, axios.get(url, {
|
|
65
|
+
validateStatus: function (status) { return status < 500; },
|
|
66
|
+
})];
|
|
67
|
+
case 1:
|
|
68
|
+
resp = _a.sent();
|
|
69
|
+
if (resp.status !== 200) {
|
|
70
|
+
throw new Error('Something went wrong.');
|
|
71
|
+
}
|
|
72
|
+
this.version = resp.data.version;
|
|
73
|
+
this.contract =
|
|
74
|
+
this.version === 1
|
|
75
|
+
? TokenCollection__factory.connect(contractAddress, signerOrProvider)
|
|
76
|
+
: TokenCollection__factoryV2.connect(contractAddress, signerOrProvider);
|
|
77
|
+
if (!this.contract) {
|
|
78
|
+
throw new Error('Initialization failed.');
|
|
79
|
+
}
|
|
80
|
+
return [2 /*return*/];
|
|
48
81
|
}
|
|
49
|
-
return [2 /*return*/];
|
|
50
82
|
});
|
|
51
83
|
});
|
|
52
84
|
};
|
|
53
|
-
Redeemable.create = function (signerOrProvider, contractAddress) {
|
|
85
|
+
Redeemable.create = function (signerOrProvider, contractAddress, isDev) {
|
|
54
86
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
87
|
var instance;
|
|
56
88
|
return __generator(this, function (_a) {
|
|
57
89
|
switch (_a.label) {
|
|
58
90
|
case 0:
|
|
59
|
-
instance = new Redeemable();
|
|
91
|
+
instance = new Redeemable(isDev);
|
|
60
92
|
return [4 /*yield*/, instance.init(signerOrProvider, contractAddress)];
|
|
61
93
|
case 1:
|
|
62
94
|
_a.sent();
|
|
@@ -65,19 +97,28 @@ var Redeemable = /** @class */ (function () {
|
|
|
65
97
|
});
|
|
66
98
|
});
|
|
67
99
|
};
|
|
68
|
-
Redeemable.prototype.
|
|
100
|
+
Redeemable.prototype.getRedeemable = function (tokenId) {
|
|
69
101
|
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
var payload;
|
|
71
|
-
return __generator(this, function (
|
|
72
|
-
switch (
|
|
73
|
-
case 0:
|
|
102
|
+
var payload, _a;
|
|
103
|
+
return __generator(this, function (_b) {
|
|
104
|
+
switch (_b.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
if (!(this.version === 1)) return [3 /*break*/, 2];
|
|
107
|
+
return [4 /*yield*/, this.contract.redeemableByIndex(tokenId)];
|
|
74
108
|
case 1:
|
|
75
|
-
|
|
109
|
+
_a = _b.sent();
|
|
110
|
+
return [3 /*break*/, 4];
|
|
111
|
+
case 2: return [4 /*yield*/, this.contract.redeemableAt(tokenId)];
|
|
112
|
+
case 3:
|
|
113
|
+
_a = _b.sent();
|
|
114
|
+
_b.label = 4;
|
|
115
|
+
case 4:
|
|
116
|
+
payload = _a;
|
|
76
117
|
return [2 /*return*/, {
|
|
77
118
|
index: tokenId,
|
|
78
|
-
tokenURI: payload
|
|
119
|
+
tokenURI: payload[0],
|
|
79
120
|
price: payload.price,
|
|
80
|
-
maxAmount: payload.
|
|
121
|
+
maxAmount: payload[3].toNumber(),
|
|
81
122
|
maxPerWallet: payload.maxPerWallet.toNumber(),
|
|
82
123
|
maxPerMint: payload.maxPerMint.toNumber(),
|
|
83
124
|
redeemedCount: payload.redeemedCount.toNumber(),
|
|
@@ -94,7 +135,7 @@ var Redeemable = /** @class */ (function () {
|
|
|
94
135
|
var nft;
|
|
95
136
|
return __generator(this, function (_a) {
|
|
96
137
|
switch (_a.label) {
|
|
97
|
-
case 0: return [4 /*yield*/, this.
|
|
138
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
98
139
|
case 1:
|
|
99
140
|
nft = _a.sent();
|
|
100
141
|
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes)'](nft.index, quantity, signature, {
|
|
@@ -110,7 +151,7 @@ var Redeemable = /** @class */ (function () {
|
|
|
110
151
|
var nft;
|
|
111
152
|
return __generator(this, function (_a) {
|
|
112
153
|
switch (_a.label) {
|
|
113
|
-
case 0: return [4 /*yield*/, this.
|
|
154
|
+
case 0: return [4 /*yield*/, this.getRedeemable(tokenId)];
|
|
114
155
|
case 1:
|
|
115
156
|
nft = _a.sent();
|
|
116
157
|
return [4 /*yield*/, this.contract['redeem(uint256,uint256,bytes,bytes32[])'](nft.index, quantity, signature, proof, {
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { Provider } from '@ethersproject/providers';
|
|
2
|
-
import { TokenCollection } from '@niftykit/contracts/typechain';
|
|
2
|
+
import { TokenCollection, TokenCollectionV2 } from '@niftykit/contracts/typechain';
|
|
3
3
|
import { ContractTransaction, Signer } from 'ethers';
|
|
4
|
-
import { RedeemableData } from '
|
|
4
|
+
import { RedeemableData } from './types/redeemable';
|
|
5
5
|
export default class Redeemable {
|
|
6
|
-
contract: TokenCollection;
|
|
6
|
+
contract: TokenCollection | TokenCollectionV2;
|
|
7
|
+
isDev?: boolean;
|
|
8
|
+
version: number;
|
|
9
|
+
private get apiBaseUrl();
|
|
10
|
+
constructor(isDev?: boolean);
|
|
7
11
|
private init;
|
|
8
|
-
static create(signerOrProvider: Signer | Provider, contractAddress: string): Promise<Redeemable | null>;
|
|
9
|
-
|
|
12
|
+
static create(signerOrProvider: Signer | Provider, contractAddress: string, isDev?: boolean): Promise<Redeemable | null>;
|
|
13
|
+
getRedeemable(tokenId: number): Promise<RedeemableData>;
|
|
10
14
|
redeem(tokenId: number, quantity: number, signature: string): Promise<ContractTransaction>;
|
|
11
15
|
presaleRedeem(tokenId: number, quantity: number, signature: string, proof: string[]): Promise<ContractTransaction>;
|
|
12
16
|
burn(tokenId: number): Promise<ContractTransaction>;
|
|
File without changes
|