@alephium/web3 0.30.1 → 0.30.2

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.
@@ -34,9 +34,11 @@ export declare class NodeProvider implements NodeProviderApis {
34
34
  static Remote(handler: ApiRequestHandler): NodeProvider;
35
35
  fetchFungibleTokenMetaData: (tokenId: HexString) => Promise<FungibleTokenMetaData>;
36
36
  fetchNFTMetaData: (tokenId: HexString) => Promise<NFTMetaData>;
37
- fetchNFTCollectionMetaData: (contractId: HexString) => Promise<NFTCollectionMetaData>;
37
+ fetchNFTCollectionMetaData: (collectionId: HexString) => Promise<NFTCollectionMetaData>;
38
+ fetchNFTRoyaltyAmount: (collectionId: HexString, tokenId: HexString, salePrice: bigint) => Promise<bigint>;
38
39
  guessStdInterfaceId: (tokenId: HexString) => Promise<HexString | undefined>;
39
40
  guessFollowsNFTCollectionStd: (contractId: HexString) => Promise<boolean>;
41
+ guessFollowsNFTCollectionWithRoyaltyStd: (contractId: HexString) => Promise<boolean>;
40
42
  guessStdTokenType: (tokenId: HexString) => Promise<'fungible' | 'non-fungible' | undefined>;
41
43
  }
42
44
  export {};
@@ -99,8 +99,8 @@ class NodeProvider {
99
99
  }
100
100
  };
101
101
  // Only use this when the contract follows the NFT collection interface, check `guessFollowsNFTCollectionStd` first
102
- this.fetchNFTCollectionMetaData = async (contractId) => {
103
- const address = (0, utils_1.addressFromContractId)(contractId);
102
+ this.fetchNFTCollectionMetaData = async (collectionId) => {
103
+ const address = (0, utils_1.addressFromContractId)(collectionId);
104
104
  const group = (0, utils_1.groupOfAddress)(address);
105
105
  const calls = Array.from([0, 1], (index) => ({ methodIndex: index, group: group, address: address }));
106
106
  const result = await this.contracts.postContractsMulticallContract({ calls });
@@ -110,6 +110,28 @@ class NodeProvider {
110
110
  totalSupply: BigInt(callResults[1].returns[0].value)
111
111
  };
112
112
  };
113
+ // Only use this when the contract follows the NFT collection with royalty interface, check `guessFollowsNFTCollectionWithRoyaltyStd` first
114
+ this.fetchNFTRoyaltyAmount = async (collectionId, tokenId, salePrice) => {
115
+ const address = (0, utils_1.addressFromContractId)(collectionId);
116
+ const group = (0, utils_1.groupOfAddress)(address);
117
+ const apiResult = await this.contracts.postContractsCallContract({
118
+ address: address,
119
+ group: group,
120
+ methodIndex: 4,
121
+ args: [
122
+ {
123
+ type: 'ByteVec',
124
+ value: tokenId
125
+ },
126
+ {
127
+ type: 'U256',
128
+ value: salePrice.toString()
129
+ }
130
+ ]
131
+ });
132
+ const result = (0, contract_1.tryGetCallResult)(apiResult);
133
+ return BigInt(result.returns[0].value);
134
+ };
113
135
  this.guessStdInterfaceId = async (tokenId) => {
114
136
  const address = (0, utils_1.addressFromTokenId)(tokenId);
115
137
  const group = (0, utils_1.groupOfAddress)(address);
@@ -127,6 +149,10 @@ class NodeProvider {
127
149
  const interfaceId = await this.guessStdInterfaceId(contractId);
128
150
  return !!interfaceId && interfaceId.startsWith(types_1.StdInterfaceIds.NFTCollection);
129
151
  };
152
+ this.guessFollowsNFTCollectionWithRoyaltyStd = async (contractId) => {
153
+ const interfaceId = await this.guessStdInterfaceId(contractId);
154
+ return interfaceId === types_1.StdInterfaceIds.NFTCollectionWithRoyalty;
155
+ };
130
156
  this.guessStdTokenType = async (tokenId) => {
131
157
  const interfaceId = await this.guessStdInterfaceId(tokenId);
132
158
  switch (interfaceId) {
@@ -57,12 +57,10 @@ export interface NFTTokenUriMetaData {
57
57
  name: string;
58
58
  description?: string;
59
59
  image: string;
60
- attributes?: [
61
- {
62
- trait_type: string;
63
- value: string | number | boolean;
64
- }
65
- ];
60
+ attributes?: {
61
+ trait_type: string;
62
+ value: string | number | boolean;
63
+ }[];
66
64
  }
67
65
  export interface NFTCollectionUriMetaData {
68
66
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.30.1",
3
+ "version": "0.30.2",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -182,8 +182,8 @@ export class NodeProvider implements NodeProviderApis {
182
182
  }
183
183
 
184
184
  // Only use this when the contract follows the NFT collection interface, check `guessFollowsNFTCollectionStd` first
185
- fetchNFTCollectionMetaData = async (contractId: HexString): Promise<NFTCollectionMetaData> => {
186
- const address = addressFromContractId(contractId)
185
+ fetchNFTCollectionMetaData = async (collectionId: HexString): Promise<NFTCollectionMetaData> => {
186
+ const address = addressFromContractId(collectionId)
187
187
  const group = groupOfAddress(address)
188
188
  const calls = Array.from([0, 1], (index) => ({ methodIndex: index, group: group, address: address }))
189
189
  const result = await this.contracts.postContractsMulticallContract({ calls })
@@ -194,6 +194,30 @@ export class NodeProvider implements NodeProviderApis {
194
194
  }
195
195
  }
196
196
 
197
+ // Only use this when the contract follows the NFT collection with royalty interface, check `guessFollowsNFTCollectionWithRoyaltyStd` first
198
+ fetchNFTRoyaltyAmount = async (collectionId: HexString, tokenId: HexString, salePrice: bigint): Promise<bigint> => {
199
+ const address = addressFromContractId(collectionId)
200
+ const group = groupOfAddress(address)
201
+ const apiResult = await this.contracts.postContractsCallContract({
202
+ address: address,
203
+ group: group,
204
+ methodIndex: 4,
205
+ args: [
206
+ {
207
+ type: 'ByteVec',
208
+ value: tokenId
209
+ },
210
+ {
211
+ type: 'U256',
212
+ value: salePrice.toString()
213
+ }
214
+ ]
215
+ })
216
+
217
+ const result = tryGetCallResult(apiResult)
218
+ return BigInt(result.returns[0].value as any as string)
219
+ }
220
+
197
221
  guessStdInterfaceId = async (tokenId: HexString): Promise<HexString | undefined> => {
198
222
  const address = addressFromTokenId(tokenId)
199
223
  const group = groupOfAddress(address)
@@ -212,6 +236,11 @@ export class NodeProvider implements NodeProviderApis {
212
236
  return !!interfaceId && interfaceId.startsWith(StdInterfaceIds.NFTCollection)
213
237
  }
214
238
 
239
+ guessFollowsNFTCollectionWithRoyaltyStd = async (contractId: HexString): Promise<boolean> => {
240
+ const interfaceId = await this.guessStdInterfaceId(contractId)
241
+ return interfaceId === StdInterfaceIds.NFTCollectionWithRoyalty
242
+ }
243
+
215
244
  guessStdTokenType = async (tokenId: HexString): Promise<'fungible' | 'non-fungible' | undefined> => {
216
245
  const interfaceId = await this.guessStdInterfaceId(tokenId)
217
246
  switch (interfaceId) {
package/src/api/types.ts CHANGED
@@ -343,12 +343,10 @@ export interface NFTTokenUriMetaData {
343
343
  name: string
344
344
  description?: string
345
345
  image: string
346
- attributes?: [
347
- {
348
- trait_type: string
349
- value: string | number | boolean
350
- }
351
- ]
346
+ attributes?: {
347
+ trait_type: string
348
+ value: string | number | boolean
349
+ }[]
352
350
  }
353
351
 
354
352
  export interface NFTCollectionUriMetaData {