git.delta.rocks / unique-network / refs/commits / 48638492add9

difftreelog

add removeFromAllowList in playgrounds

rkv2022-09-09parent: #fd44216.patch.diff
in: master

2 files changed

modifiedtests/src/allowLists.test.tsdiffbeforeafterboth
25let donor: IKeyringPair;25let donor: IKeyringPair;
2626
27before(async () => {27before(async () => {
28 await usingPlaygrounds(async (_, privateKeyWrapper) => {28 await usingPlaygrounds(async (_, privateKey) => {
29 donor = privateKeyWrapper('//Alice');29 donor = privateKey('//Alice');
30 });30 });
31});31});
3232
66 await usingPlaygrounds(async (helper) => {66 await usingPlaygrounds(async (helper) => {
67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
68 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});68 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
69 expect(addToAllowListTx()).to.be.rejected;69 await expect(addToAllowListTx()).to.be.rejected;
70 });70 });
71 });71 });
7272
73 it('Nobody can add address to allow list of non-existing collection', async () => {73 it('Nobody can add address to allow list of non-existing collection', async () => {
74 const collectionId = (1<<32) - 1;74 const collectionId = (1<<32) - 1;
75 await usingPlaygrounds(async (helper) => {75 await usingPlaygrounds(async (helper) => {
76 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});76 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
77 expect(addToAllowListTx()).to.be.rejected;77 await expect(addToAllowListTx()).to.be.rejected;
78 });78 });
79 });79 });
8080
83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
84 await helper.collection.burn(alice, collectionId);84 await helper.collection.burn(alice, collectionId);
85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
86 expect(addToAllowListTx()).to.be.rejected;86 await expect(addToAllowListTx()).to.be.rejected;
87 });87 });
88 });88 });
8989
102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
104104
105 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
106 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);105 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
107106
108 const allowList = await helper.nft.getAllowList(collectionId);107 const allowList = await helper.nft.getAllowList(collectionId);
109108
116 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});115 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
117 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});116 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});
118 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});117 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
119 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
120 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(charlie);118 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});
121119
122 const allowList = await helper.nft.getAllowList(collectionId);120 const allowList = await helper.nft.getAllowList(collectionId);
123121
129 await usingPlaygrounds(async (helper) => {127 await usingPlaygrounds(async (helper) => {
130 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});128 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
131 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});129 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
132 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
133 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob);130 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
134131 await expect(removeTx()).to.be.rejected;
135 const allowList = await helper.nft.getAllowList(collectionId);132 const allowList = await helper.nft.getAllowList(collectionId);
136133
137 expect(allowList).to.be.deep.contains({Substrate: charlie.address});134 expect(allowList).to.be.deep.contains({Substrate: charlie.address});
141 it('Nobody can remove address from allow list of non-existing collection', async () => {138 it('Nobody can remove address from allow list of non-existing collection', async () => {
142 const collectionId = (1<<32) - 1;139 const collectionId = (1<<32) - 1;
143 await usingPlaygrounds(async (helper) => {140 await usingPlaygrounds(async (helper) => {
144 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
145 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob);141 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
146
147 const allowList = await helper.nft.getAllowList(collectionId);
148
149 expect(allowList).to.be.not.deep.contains({Substrate: charlie.address});142 await expect(removeTx()).to.be.rejected;
150 });143 });
151 });144 });
152145
156 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});149 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
157 await helper.collection.burn(alice, collectionId);150 await helper.collection.burn(alice, collectionId);
158
159 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
160 const removeTx = async () => helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);151 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
161152
162 expect(removeTx()).to.be.rejected;153 await expect(removeTx()).to.be.rejected;
163 });154 });
164 });155 });
165156
168 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});159 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
169 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});160 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
170
171 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
172 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);161 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
173 const allowListBefore = await helper.nft.getAllowList(collectionId);162 const allowListBefore = await helper.nft.getAllowList(collectionId);
174 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});163 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});
175164
176 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);165 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
177166
178 const allowListAfter = await helper.nft.getAllowList(collectionId);167 const allowListAfter = await helper.nft.getAllowList(collectionId);
179 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});168 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});
188 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});177 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
189178
190 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});179 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
191 expect(transferResult()).to.be.rejected;180 await expect(transferResult()).to.be.rejected;
192 });181 });
193 });182 });
194183
201 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});190 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
202 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});191 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
203
204 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
205 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice);192 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
206193
207 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});194 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
208 expect(transferResult()).to.be.rejected;195 await expect(transferResult()).to.be.rejected;
209 });196 });
210 });197 });
211198
217 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});204 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
218205
219 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});206 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
220 expect(transferResult()).to.be.rejected;207 await expect(transferResult()).to.be.rejected;
221 });208 });
222 });209 });
223210
231218
232 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});219 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
233
234 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
235 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice);220 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
236221
237 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});222 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
238 expect(transferResult()).to.be.rejected;223 await expect(transferResult()).to.be.rejected;
239 });224 });
240 });225 });
241226
245 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});230 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
246 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});231 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
247 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);232 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);
248 expect(burnTx()).to.be.rejected;233 await expect(burnTx()).to.be.rejected;
249 });234 });
250 });235 });
251236
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
464 return (await this.helper.callRpc('api.rpc.unique.nextSponsored', [collectionId, addressObj, tokenId])).toJSON();464 return (await this.helper.callRpc('api.rpc.unique.nextSponsored', [collectionId, addressObj, tokenId])).toJSON();
465 }465 }
466466
467 /**467 /**
468 * Get the number of created collections.468 * Get the number of created collections.
469 * 469 *
470 * @returns number of created collections470 * @returns number of created collections
471 */471 */
472 async getTotalCount(): Promise<number> {472 async getTotalCount(): Promise<number> {
473 return (await this.helper.callRpc('api.rpc.unique.collectionStats')).created.toNumber();473 return (await this.helper.callRpc('api.rpc.unique.collectionStats')).created.toNumber();
474 }474 }
475475
476 /**476 /**
477 * Get information about the collection with additional data, including the number of tokens it contains, its administrators, the normalized address of the collection's owner, and decoded name and description.477 * Get information about the collection with additional data, including the number of tokens it contains, its administrators, the normalized address of the collection's owner, and decoded name and description.
478 * 478 *
479 * @param collectionId ID of collection479 * @param collectionId ID of collection
480 * @example await getData(2)480 * @example await getData(2)
481 * @returns collection information object481 * @returns collection information object
482 */482 */
483 async getData(collectionId: number): Promise<{483 async getData(collectionId: number): Promise<{
484 id: number;484 id: number;
485 name: string;485 name: string;
508 return collectionData;508 return collectionData;
509 }509 }
510510
511 /**511 /**
512 * Get the normalized addresses of the collection's administrators.512 * Get the normalized addresses of the collection's administrators.
513 * 513 *
514 * @param collectionId ID of collection514 * @param collectionId ID of collection
515 * @example await getAdmins(1)515 * @example await getAdmins(1)
516 * @returns array of administrators516 * @returns array of administrators
517 */517 */
518 async getAdmins(collectionId: number): Promise<ICrossAccountId[]> {518 async getAdmins(collectionId: number): Promise<ICrossAccountId[]> {
519 const normalized = [];519 const normalized = [];
520 for(const admin of (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman()) {520 for(const admin of (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman()) {
540 return normalized;540 return normalized;
541 }541 }
542542
543 /**543 /**
544 * Get the effective limits of the collection instead of null for default values544 * Get the effective limits of the collection instead of null for default values
545 * 545 *
546 * @param collectionId ID of collection546 * @param collectionId ID of collection
547 * @example await getEffectiveLimits(2)547 * @example await getEffectiveLimits(2)
548 * @returns object of collection limits548 * @returns object of collection limits
549 */549 */
550 async getEffectiveLimits(collectionId: number): Promise<ICollectionLimits> {550 async getEffectiveLimits(collectionId: number): Promise<ICollectionLimits> {
551 return (await this.helper.callRpc('api.rpc.unique.effectiveCollectionLimits', [collectionId])).toJSON();551 return (await this.helper.callRpc('api.rpc.unique.effectiveCollectionLimits', [collectionId])).toJSON();
552 }552 }
553553
554 /**554 /**
555 * Burns the collection if the signer has sufficient permissions and collection is empty.555 * Burns the collection if the signer has sufficient permissions and collection is empty.
556 * 556 *
557 * @param signer keyring of signer557 * @param signer keyring of signer
558 * @param collectionId ID of collection558 * @param collectionId ID of collection
559 * @param label extra label for log559 * @param label extra label for log
560 * @example await helper.collection.burn(aliceKeyring, 3);560 * @example await helper.collection.burn(aliceKeyring, 3);
561 * @returns ```true``` if extrinsic success, otherwise ```false```561 * @returns ```true``` if extrinsic success, otherwise ```false```
562 */562 */
563 async burn(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {563 async burn(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {
564 if(typeof label === 'undefined') label = `collection #${collectionId}`;564 if(typeof label === 'undefined') label = `collection #${collectionId}`;
565 const result = await this.helper.executeExtrinsic(565 const result = await this.helper.executeExtrinsic(
571 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed', label);571 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed', label);
572 }572 }
573573
574 /**574 /**
575 * Sets the sponsor for the collection (Requires the Substrate address).575 * Sets the sponsor for the collection (Requires the Substrate address).
576 * 576 *
577 * @param signer keyring of signer577 * @param signer keyring of signer
578 * @param collectionId ID of collection578 * @param collectionId ID of collection
579 * @param sponsorAddress Sponsor substrate address579 * @param sponsorAddress Sponsor substrate address
580 * @param label extra label for log580 * @param label extra label for log
581 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")581 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")
582 * @returns ```true``` if extrinsic success, otherwise ```false```582 * @returns ```true``` if extrinsic success, otherwise ```false```
583 */583 */
584 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount, label?: string): Promise<boolean> {584 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount, label?: string): Promise<boolean> {
585 if(typeof label === 'undefined') label = `collection #${collectionId}`;585 if(typeof label === 'undefined') label = `collection #${collectionId}`;
586 const result = await this.helper.executeExtrinsic(586 const result = await this.helper.executeExtrinsic(
592 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet', label);592 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet', label);
593 }593 }
594594
595 /**595 /**
596 * Confirms consent to sponsor the collection on behalf of the signer.596 * Confirms consent to sponsor the collection on behalf of the signer.
597 * 597 *
598 * @param signer keyring of signer598 * @param signer keyring of signer
599 * @param collectionId ID of collection599 * @param collectionId ID of collection
600 * @param label extra label for log600 * @param label extra label for log
601 * @example confirmSponsorship(aliceKeyring, 10)601 * @example confirmSponsorship(aliceKeyring, 10)
602 * @returns ```true``` if extrinsic success, otherwise ```false```602 * @returns ```true``` if extrinsic success, otherwise ```false```
603 */603 */
604 async confirmSponsorship(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {604 async confirmSponsorship(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {
605 if(typeof label === 'undefined') label = `collection #${collectionId}`;605 if(typeof label === 'undefined') label = `collection #${collectionId}`;
606 const result = await this.helper.executeExtrinsic(606 const result = await this.helper.executeExtrinsic(
612 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed', label);612 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed', label);
613 }613 }
614614
615 /**615 /**
616 * Sets the limits of the collection. At least one limit must be specified for a correct call.616 * Sets the limits of the collection. At least one limit must be specified for a correct call.
617 * 617 *
618 * @param signer keyring of signer618 * @param signer keyring of signer
619 * @param collectionId ID of collection619 * @param collectionId ID of collection
620 * @param limits collection limits object620 * @param limits collection limits object
621 * @param label extra label for log621 * @param label extra label for log
622 * @example622 * @example
623 * await setLimits(623 * await setLimits(
624 * aliceKeyring,624 * aliceKeyring,
625 * 10,625 * 10,
626 * {626 * {
627 * sponsorTransferTimeout: 0,627 * sponsorTransferTimeout: 0,
628 * ownerCanDestroy: false628 * ownerCanDestroy: false
629 * }629 * }
630 * )630 * )
631 * @returns ```true``` if extrinsic success, otherwise ```false```631 * @returns ```true``` if extrinsic success, otherwise ```false```
632 */632 */
633 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits, label?: string): Promise<boolean> {633 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits, label?: string): Promise<boolean> {
634 if(typeof label === 'undefined') label = `collection #${collectionId}`;634 if(typeof label === 'undefined') label = `collection #${collectionId}`;
635 const result = await this.helper.executeExtrinsic(635 const result = await this.helper.executeExtrinsic(
641 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet', label);641 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet', label);
642 }642 }
643643
644 /**644 /**
645 * Changes the owner of the collection to the new Substrate address.645 * Changes the owner of the collection to the new Substrate address.
646 * 646 *
647 * @param signer keyring of signer647 * @param signer keyring of signer
648 * @param collectionId ID of collection648 * @param collectionId ID of collection
649 * @param ownerAddress substrate address of new owner649 * @param ownerAddress substrate address of new owner
650 * @param label extra label for log650 * @param label extra label for log
651 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")651 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")
652 * @returns ```true``` if extrinsic success, otherwise ```false```652 * @returns ```true``` if extrinsic success, otherwise ```false```
653 */653 */
654 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount, label?: string): Promise<boolean> {654 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount, label?: string): Promise<boolean> {
655 if(typeof label === 'undefined') label = `collection #${collectionId}`;655 if(typeof label === 'undefined') label = `collection #${collectionId}`;
656 const result = await this.helper.executeExtrinsic(656 const result = await this.helper.executeExtrinsic(
662 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged', label);662 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged', label);
663 }663 }
664664
665 /**665 /**
666 * Adds a collection administrator. 666 * Adds a collection administrator.
667 * 667 *
668 * @param signer keyring of signer668 * @param signer keyring of signer
669 * @param collectionId ID of collection669 * @param collectionId ID of collection
670 * @param adminAddressObj Administrator address (substrate or ethereum)670 * @param adminAddressObj Administrator address (substrate or ethereum)
671 * @param label extra label for log671 * @param label extra label for log
672 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})672 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})
673 * @returns ```true``` if extrinsic success, otherwise ```false```673 * @returns ```true``` if extrinsic success, otherwise ```false```
674 */674 */
675 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {675 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {
676 if(typeof label === 'undefined') label = `collection #${collectionId}`;676 if(typeof label === 'undefined') label = `collection #${collectionId}`;
677 const result = await this.helper.executeExtrinsic(677 const result = await this.helper.executeExtrinsic(
683 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded', label);683 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded', label);
684 }684 }
685685
686 /**686 /**
687 * Adds an address to allow list 687 * Adds an address to allow list
688 * @param signer keyring of signer688 * @param signer keyring of signer
689 * @param collectionId ID of collection689 * @param collectionId ID of collection
690 * @param addressObj address to add to the allow list690 * @param addressObj address to add to the allow list
691 * @param label extra label for log691 * @param label extra label for log
692 * @returns ```true``` if extrinsic success, otherwise ```false```692 * @returns ```true``` if extrinsic success, otherwise ```false```
693 */693 */
694 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId, label?: string): Promise<boolean> {694 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId, label?: string): Promise<boolean> {
695 if(typeof label === 'undefined') label = `collection #${collectionId}`;695 if(typeof label === 'undefined') label = `collection #${collectionId}`;
696 const result = await this.helper.executeExtrinsic(696 const result = await this.helper.executeExtrinsic(
702 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');702 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');
703 }703 }
704
705 /**
706 * Removes an address from allow list.
707 *
708 * @param signer keyring of signer
709 * @param collectionId ID of collection
710 * @param addressObj address to be removed from allow list (substrate or ethereum)
711 * @param label extra label for log
712 * @example removeFromAllowList(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})
713 * @returns ```true``` if extrinsic success, otherwise ```false```
714 */
715 async removeFromAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId, label?: string): Promise<boolean> {
716 if(typeof label === 'undefined') label = `collection #${collectionId}`;
717 const result = await this.helper.executeExtrinsic(
718 signer,
719 'api.tx.unique.removeFromAllowList', [collectionId, addressObj],
720 true, `Unable to remove address from allow list for ${label}`,
721 );
722
723 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressRemoved', label);
724 }
704725
705 /**726 /**
706 * Removes a collection administrator.727 * Removes a collection administrator.
707 * 728 *
708 * @param signer keyring of signer729 * @param signer keyring of signer
709 * @param collectionId ID of collection730 * @param collectionId ID of collection
710 * @param adminAddressObj Administrator address (substrate or ethereum)731 * @param adminAddressObj Administrator address (substrate or ethereum)
711 * @param label extra label for log732 * @param label extra label for log
712 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})733 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})
713 * @returns ```true``` if extrinsic success, otherwise ```false```734 * @returns ```true``` if extrinsic success, otherwise ```false```
714 */735 */
715 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {736 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {
716 if(typeof label === 'undefined') label = `collection #${collectionId}`;737 if(typeof label === 'undefined') label = `collection #${collectionId}`;
717 const result = await this.helper.executeExtrinsic(738 const result = await this.helper.executeExtrinsic(
723 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved', label);744 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved', label);
724 }745 }
725746
726 /**747 /**
727 * Sets onchain permissions for selected collection.748 * Sets onchain permissions for selected collection.
728 * 749 *
729 * @param signer keyring of signer750 * @param signer keyring of signer
730 * @param collectionId ID of collection751 * @param collectionId ID of collection
731 * @param permissions collection permissions object752 * @param permissions collection permissions object
732 * @param label extra label for log753 * @param label extra label for log
733 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});754 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});
734 * @returns ```true``` if extrinsic success, otherwise ```false```755 * @returns ```true``` if extrinsic success, otherwise ```false```
735 */756 */
736 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions, label?: string): Promise<boolean> {757 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions, label?: string): Promise<boolean> {
737 if(typeof label === 'undefined') label = `collection #${collectionId}`;758 if(typeof label === 'undefined') label = `collection #${collectionId}`;
738 const result = await this.helper.executeExtrinsic(759 const result = await this.helper.executeExtrinsic(
744 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet', label);765 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet', label);
745 }766 }
746767
747 /**768 /**
748 * Enables nesting for selected collection. If `restricted` set, you can nest only tokens from specified collections.769 * Enables nesting for selected collection. If `restricted` set, you can nest only tokens from specified collections.
749 * 770 *
750 * @param signer keyring of signer771 * @param signer keyring of signer
751 * @param collectionId ID of collection772 * @param collectionId ID of collection
752 * @param permissions nesting permissions object773 * @param permissions nesting permissions object
753 * @param label extra label for log774 * @param label extra label for log
754 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});775 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});
755 * @returns ```true``` if extrinsic success, otherwise ```false```776 * @returns ```true``` if extrinsic success, otherwise ```false```
756 */777 */
757 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions, label?: string): Promise<boolean> {778 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions, label?: string): Promise<boolean> {
758 return await this.setPermissions(signer, collectionId, {nesting: permissions}, label);779 return await this.setPermissions(signer, collectionId, {nesting: permissions}, label);
759 }780 }
760781
761 /**782 /**
762 * Disables nesting for selected collection.783 * Disables nesting for selected collection.
763 * 784 *
764 * @param signer keyring of signer785 * @param signer keyring of signer
765 * @param collectionId ID of collection786 * @param collectionId ID of collection
766 * @param label extra label for log787 * @param label extra label for log
767 * @example disableNesting(aliceKeyring, 10);788 * @example disableNesting(aliceKeyring, 10);
768 * @returns ```true``` if extrinsic success, otherwise ```false```789 * @returns ```true``` if extrinsic success, otherwise ```false```
769 */790 */
770 async disableNesting(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {791 async disableNesting(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {
771 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}}, label);792 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}}, label);
772 }793 }
773794
774 /**795 /**
775 * Sets onchain properties to the collection.796 * Sets onchain properties to the collection.
776 * 797 *
777 * @param signer keyring of signer798 * @param signer keyring of signer
778 * @param collectionId ID of collection799 * @param collectionId ID of collection
779 * @param properties array of property objects800 * @param properties array of property objects
780 * @param label extra label for log801 * @param label extra label for log
781 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);802 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);
782 * @returns ```true``` if extrinsic success, otherwise ```false```803 * @returns ```true``` if extrinsic success, otherwise ```false```
783 */804 */
784 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[], label?: string): Promise<boolean> {805 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[], label?: string): Promise<boolean> {
785 if(typeof label === 'undefined') label = `collection #${collectionId}`;806 if(typeof label === 'undefined') label = `collection #${collectionId}`;
786 const result = await this.helper.executeExtrinsic(807 const result = await this.helper.executeExtrinsic(
792 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet', label);813 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet', label);
793 }814 }
794815
795 /**816 /**
796 * Deletes onchain properties from the collection.817 * Deletes onchain properties from the collection.
797 * 818 *
798 * @param signer keyring of signer819 * @param signer keyring of signer
799 * @param collectionId ID of collection820 * @param collectionId ID of collection
800 * @param propertyKeys array of property keys to delete821 * @param propertyKeys array of property keys to delete
801 * @param label822 * @param label
802 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);823 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);
803 * @returns ```true``` if extrinsic success, otherwise ```false```824 * @returns ```true``` if extrinsic success, otherwise ```false```
804 */825 */
805 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[], label?: string): Promise<boolean> {826 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[], label?: string): Promise<boolean> {
806 if(typeof label === 'undefined') label = `collection #${collectionId}`;827 if(typeof label === 'undefined') label = `collection #${collectionId}`;
807 const result = await this.helper.executeExtrinsic(828 const result = await this.helper.executeExtrinsic(
813 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted', label);834 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted', label);
814 }835 }
815836
816 /**837 /**
817 * Changes the owner of the token.838 * Changes the owner of the token.
818 * 839 *
819 * @param signer keyring of signer840 * @param signer keyring of signer
820 * @param collectionId ID of collection841 * @param collectionId ID of collection
821 * @param tokenId ID of token842 * @param tokenId ID of token
822 * @param addressObj address of a new owner843 * @param addressObj address of a new owner
823 * @param amount amount of tokens to be transfered. For NFT must be set to 1n844 * @param amount amount of tokens to be transfered. For NFT must be set to 1n
824 * @example transferToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})845 * @example transferToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})
825 * @returns true if the token success, otherwise false846 * @returns true if the token success, otherwise false
826 */847 */
827 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=1n): Promise<boolean> {848 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=1n): Promise<boolean> {
828 const result = await this.helper.executeExtrinsic(849 const result = await this.helper.executeExtrinsic(
829 signer,850 signer,
834 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);855 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);
835 }856 }
836857
837 /**858 /**
838 * 859 *
839 * Change ownership of a token(s) on behalf of the owner. 860 * Change ownership of a token(s) on behalf of the owner.
840 * 861 *
841 * @param signer keyring of signer862 * @param signer keyring of signer
842 * @param collectionId ID of collection863 * @param collectionId ID of collection
843 * @param tokenId ID of token864 * @param tokenId ID of token
844 * @param fromAddressObj address on behalf of which the token will be sent865 * @param fromAddressObj address on behalf of which the token will be sent
845 * @param toAddressObj new token owner866 * @param toAddressObj new token owner
846 * @param amount amount of tokens to be transfered. For NFT must be set to 1n867 * @param amount amount of tokens to be transfered. For NFT must be set to 1n
847 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg"}, {Ethereum: "0x9F0583DbB85..."})868 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg"}, {Ethereum: "0x9F0583DbB85..."})
848 * @returns true if the token success, otherwise false869 * @returns true if the token success, otherwise false
849 */870 */
850 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {871 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {
851 const result = await this.helper.executeExtrinsic(872 const result = await this.helper.executeExtrinsic(
852 signer,873 signer,
856 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);877 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);
857 }878 }
858879
859 /**880 /**
860 * 881 *
861 * Destroys a concrete instance of NFT/RFT or burns a specified amount of fungible tokens.882 * Destroys a concrete instance of NFT/RFT or burns a specified amount of fungible tokens.
862 * 883 *
863 * @param signer keyring of signer884 * @param signer keyring of signer
864 * @param collectionId ID of collection885 * @param collectionId ID of collection
865 * @param tokenId ID of token886 * @param tokenId ID of token
866 * @param label 887 * @param label
867 * @param amount amount of tokens to be burned. For NFT must be set to 1n888 * @param amount amount of tokens to be burned. For NFT must be set to 1n
868 * @example burnToken(aliceKeyring, 10, 5);889 * @example burnToken(aliceKeyring, 10, 5);
869 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```890 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
870 */891 */
871 async burnToken(signer: TSigner, collectionId: number, tokenId: number, label?: string, amount=1n): Promise<{892 async burnToken(signer: TSigner, collectionId: number, tokenId: number, label?: string, amount=1n): Promise<{
872 success: boolean,893 success: boolean,
873 token: number | null894 token: number | null
883 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};904 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};
884 }905 }
885906
886 /**907 /**
887 * Destroys a concrete instance of NFT on behalf of the owner908 * Destroys a concrete instance of NFT on behalf of the owner
888 * 909 *
889 * @param signer keyring of signer910 * @param signer keyring of signer
890 * @param collectionId ID of collection911 * @param collectionId ID of collection
891 * @param fromAddressObj address on behalf of which the token will be burnt912 * @param fromAddressObj address on behalf of which the token will be burnt
892 * @param tokenId ID of token913 * @param tokenId ID of token
893 * @param label 914 * @param label
894 * @param amount amount of tokens to be burned. For NFT must be set to 1n915 * @param amount amount of tokens to be burned. For NFT must be set to 1n
895 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})916 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})
896 * @returns ```true``` if extrinsic success, otherwise ```false```917 * @returns ```true``` if extrinsic success, otherwise ```false```
897 */918 */
898 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, label?: string, amount=1n): Promise<boolean> {919 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, label?: string, amount=1n): Promise<boolean> {
899 if(typeof label === 'undefined') label = `collection #${collectionId}`;920 if(typeof label === 'undefined') label = `collection #${collectionId}`;
900 const burnResult = await this.helper.executeExtrinsic(921 const burnResult = await this.helper.executeExtrinsic(
906 return burnedTokens.success && burnedTokens.tokens.length > 0;927 return burnedTokens.success && burnedTokens.tokens.length > 0;
907 }928 }
908929
909 /**930 /**
910 * Set, change, or remove approved address to transfer the ownership of the NFT.931 * Set, change, or remove approved address to transfer the ownership of the NFT.
911 * 932 *
912 * @param signer keyring of signer933 * @param signer keyring of signer
913 * @param collectionId ID of collection934 * @param collectionId ID of collection
914 * @param tokenId ID of token935 * @param tokenId ID of token
915 * @param toAddressObj 936 * @param toAddressObj
916 * @param label 937 * @param label
917 * @param amount amount of token to be approved. For NFT must be set to 1n938 * @param amount amount of token to be approved. For NFT must be set to 1n
918 * @returns ```true``` if extrinsic success, otherwise ```false```939 * @returns ```true``` if extrinsic success, otherwise ```false```
919 */940 */
920 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=1n) {941 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=1n) {
921 if(typeof label === 'undefined') label = `collection #${collectionId}`;942 if(typeof label === 'undefined') label = `collection #${collectionId}`;
922 const approveResult = await this.helper.executeExtrinsic(943 const approveResult = await this.helper.executeExtrinsic(
928 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved', label);949 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved', label);
929 }950 }
930951
931 /**952 /**
932 * Get the amount of token pieces approved to transfer953 * Get the amount of token pieces approved to transfer
933 * @param collectionId ID of collection954 * @param collectionId ID of collection
934 * @param tokenId ID of token955 * @param tokenId ID of token
935 * @param toAccountObj 956 * @param toAccountObj
936 * @param fromAccountObj957 * @param fromAccountObj
937 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})958 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})
938 * @returns number of approved to transfer pieces959 * @returns number of approved to transfer pieces
939 */960 */
940 async getTokenApprovedPieces(collectionId: number, tokenId: number, toAccountObj: ICrossAccountId, fromAccountObj: ICrossAccountId): Promise<bigint> {961 async getTokenApprovedPieces(collectionId: number, tokenId: number, toAccountObj: ICrossAccountId, fromAccountObj: ICrossAccountId): Promise<bigint> {
941 return (await this.helper.callRpc('api.rpc.unique.allowance', [collectionId, fromAccountObj, toAccountObj, tokenId])).toBigInt();962 return (await this.helper.callRpc('api.rpc.unique.allowance', [collectionId, fromAccountObj, toAccountObj, tokenId])).toBigInt();
942 }963 }
964}985}
965986
966class NFTnRFT extends CollectionGroup {987class NFTnRFT extends CollectionGroup {
967 /**988 /**
968 * Get tokens owned by account989 * Get tokens owned by account
969 * 990 *
970 * @param collectionId ID of collection991 * @param collectionId ID of collection
971 * @param addressObj tokens owner992 * @param addressObj tokens owner
972 * @example getTokensByAddress(10, {Substrate: "5DyN4Y92vZCjv38fg..."})993 * @example getTokensByAddress(10, {Substrate: "5DyN4Y92vZCjv38fg..."})
973 * @returns array of token ids owned by account994 * @returns array of token ids owned by account
974 */995 */
975 async getTokensByAddress(collectionId: number, addressObj: ICrossAccountId): Promise<number[]> {996 async getTokensByAddress(collectionId: number, addressObj: ICrossAccountId): Promise<number[]> {
976 return (await this.helper.callRpc('api.rpc.unique.accountTokens', [collectionId, addressObj])).toJSON();997 return (await this.helper.callRpc('api.rpc.unique.accountTokens', [collectionId, addressObj])).toJSON();
977 }998 }
978999
979 /**1000 /**
980 * Get token data1001 * Get token data
981 * @param collectionId ID of collection1002 * @param collectionId ID of collection
982 * @param tokenId ID of token1003 * @param tokenId ID of token
983 * @param blockHashAt 1004 * @param blockHashAt
984 * @param propertyKeys1005 * @param propertyKeys
985 * @example getToken(10, 5);1006 * @example getToken(10, 5);
986 * @returns human readable token data 1007 * @returns human readable token data
987 */1008 */
988 async getToken(collectionId: number, tokenId: number, blockHashAt?: string, propertyKeys?: string[]): Promise<{1009 async getToken(collectionId: number, tokenId: number, blockHashAt?: string, propertyKeys?: string[]): Promise<{
989 properties: IProperty[];1010 properties: IProperty[];
990 owner: ICrossAccountId;1011 owner: ICrossAccountId;
1012 return tokenData;1033 return tokenData;
1013 }1034 }
10141035
1015 /**1036 /**
1016 * Set permissions to change token properties1037 * Set permissions to change token properties
1017 * @param signer keyring of signer1038 * @param signer keyring of signer
1018 * @param collectionId ID of collection1039 * @param collectionId ID of collection
1019 * @param permissions permissions to change a property by the collection owner or admin1040 * @param permissions permissions to change a property by the collection owner or admin
1020 * @param label 1041 * @param label
1021 * @example setTokenPropertyPermissions(1042 * @example setTokenPropertyPermissions(
1022 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]1043 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]
1023 * )1044 * )
1024 * @returns true if extrinsic success otherwise false1045 * @returns true if extrinsic success otherwise false
1025 */1046 */
1026 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[], label?: string): Promise<boolean> {1047 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[], label?: string): Promise<boolean> {
1027 if(typeof label === 'undefined') label = `collection #${collectionId}`;1048 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1028 const result = await this.helper.executeExtrinsic(1049 const result = await this.helper.executeExtrinsic(
1034 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet', label);1055 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet', label);
1035 }1056 }
10361057
1037 /**1058 /**
1038 * Set token properties1059 * Set token properties
1039 * @param signer keyring of signer1060 * @param signer keyring of signer
1040 * @param collectionId ID of collection1061 * @param collectionId ID of collection
1041 * @param tokenId ID of token1062 * @param tokenId ID of token
1042 * @param properties 1063 * @param properties
1043 * @param label 1064 * @param label
1044 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1065 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])
1045 * @returns ```true``` if extrinsic success, otherwise ```false```1066 * @returns ```true``` if extrinsic success, otherwise ```false```
1046 */1067 */
1047 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[], label?: string): Promise<boolean> {1068 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[], label?: string): Promise<boolean> {
1048 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;1069 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;
1049 const result = await this.helper.executeExtrinsic(1070 const result = await this.helper.executeExtrinsic(
1055 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet', label);1076 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet', label);
1056 }1077 }
10571078
1058 /**1079 /**
1059 * Delete the provided properties of a token1080 * Delete the provided properties of a token
1060 * @param signer keyring of signer1081 * @param signer keyring of signer
1061 * @param collectionId ID of collection1082 * @param collectionId ID of collection
1062 * @param tokenId ID of token1083 * @param tokenId ID of token
1063 * @param propertyKeys property keys to be deleted 1084 * @param propertyKeys property keys to be deleted
1064 * @param label 1085 * @param label
1065 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])1086 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])
1066 * @returns ```true``` if extrinsic success, otherwise ```false```1087 * @returns ```true``` if extrinsic success, otherwise ```false```
1067 */1088 */
1068 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[], label?: string): Promise<boolean> {1089 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[], label?: string): Promise<boolean> {
1069 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;1090 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;
1070 const result = await this.helper.executeExtrinsic(1091 const result = await this.helper.executeExtrinsic(
1076 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted', label);1097 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted', label);
1077 }1098 }
10781099
1079 /**1100 /**
1080 * Mint new collection1101 * Mint new collection
1081 * @param signer keyring of signer1102 * @param signer keyring of signer
1082 * @param collectionOptions basic collection options and properties 1103 * @param collectionOptions basic collection options and properties
1083 * @param mode NFT or RFT type of a collection1104 * @param mode NFT or RFT type of a collection
1084 * @param errorLabel 1105 * @param errorLabel
1085 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")1106 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")
1086 * @returns object of the created collection1107 * @returns object of the created collection
1087 */1108 */
1088 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT', errorLabel = 'Unable to mint collection'): Promise<UniqueCollectionBase> {1109 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT', errorLabel = 'Unable to mint collection'): Promise<UniqueCollectionBase> {
1089 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1110 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object
1090 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};1111 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};
1131 return new UniqueNFTToken(tokenId, this.getCollectionObject(collectionId));1152 return new UniqueNFTToken(tokenId, this.getCollectionObject(collectionId));
1132 }1153 }
11331154
1134 /**1155 /**
1135 * Get token's owner1156 * Get token's owner
1136 * @param collectionId ID of collection1157 * @param collectionId ID of collection
1137 * @param tokenId ID of token1158 * @param tokenId ID of token
1138 * @param blockHashAt 1159 * @param blockHashAt
1139 * @example getTokenOwner(10, 5);1160 * @example getTokenOwner(10, 5);
1140 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1161 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}
1141 */1162 */
1142 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId> {1163 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId> {
1143 let owner;1164 let owner;
1144 if (typeof blockHashAt === 'undefined') {1165 if (typeof blockHashAt === 'undefined') {
1160 return (await this.getTokenApprovedPieces(collectionId, tokenId, toAccountObj, await this.getTokenOwner(collectionId, tokenId))) === 1n;1181 return (await this.getTokenApprovedPieces(collectionId, tokenId, toAccountObj, await this.getTokenOwner(collectionId, tokenId))) === 1n;
1161 }1182 }
11621183
1163 /**1184 /**
1164 * Changes the owner of the token.1185 * Changes the owner of the token.
1165 * 1186 *
1166 * @param signer keyring of signer1187 * @param signer keyring of signer
1167 * @param collectionId ID of collection1188 * @param collectionId ID of collection
1168 * @param tokenId ID of token1189 * @param tokenId ID of token
1169 * @param addressObj address of a new owner1190 * @param addressObj address of a new owner
1170 * @example transferToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1191 * @example transferToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})
1171 * @returns ```true``` if extrinsic success, otherwise ```false```1192 * @returns ```true``` if extrinsic success, otherwise ```false```
1172 */1193 */
1173 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId): Promise<boolean> {1194 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId): Promise<boolean> {
1174 return await super.transferToken(signer, collectionId, tokenId, addressObj, 1n);1195 return await super.transferToken(signer, collectionId, tokenId, addressObj, 1n);
1175 }1196 }
11761197
1177 /**1198 /**
1178 * 1199 *
1179 * Change ownership of a NFT on behalf of the owner. 1200 * Change ownership of a NFT on behalf of the owner.
1180 * 1201 *
1181 * @param signer keyring of signer1202 * @param signer keyring of signer
1182 * @param collectionId ID of collection1203 * @param collectionId ID of collection
1183 * @param tokenId ID of token1204 * @param tokenId ID of token
1184 * @param fromAddressObj address on behalf of which the token will be sent1205 * @param fromAddressObj address on behalf of which the token will be sent
1185 * @param toAddressObj new token owner1206 * @param toAddressObj new token owner
1186 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Ethereum: "0x9F0583DbB85..."})1207 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Ethereum: "0x9F0583DbB85..."})
1187 * @returns ```true``` if extrinsic success, otherwise ```false```1208 * @returns ```true``` if extrinsic success, otherwise ```false```
1188 */1209 */
1189 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId): Promise<boolean> {1210 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId): Promise<boolean> {
1190 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, 1n);1211 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, 1n);
1191 }1212 }
11921213
1193 /**1214 /**
1194 * Recursively find the address that owns the token1215 * Recursively find the address that owns the token
1195 * @param collectionId ID of collection1216 * @param collectionId ID of collection
1196 * @param tokenId ID of token1217 * @param tokenId ID of token
1197 * @param blockHashAt 1218 * @param blockHashAt
1198 * @example getTokenTopmostOwner(10, 5);1219 * @example getTokenTopmostOwner(10, 5);
1199 * @returns address in CrossAccountId format, e.g. {Substrate: "5DyN4Y92vZCjv38fg..."}1220 * @returns address in CrossAccountId format, e.g. {Substrate: "5DyN4Y92vZCjv38fg..."}
1200 */1221 */
1201 async getTokenTopmostOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId | null> {1222 async getTokenTopmostOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId | null> {
1202 let owner;1223 let owner;
1203 if (typeof blockHashAt === 'undefined') {1224 if (typeof blockHashAt === 'undefined') {
1213 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;1234 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;
1214 }1235 }
12151236
1216 /**1237 /**
1217 * Get tokens nested in the provided token1238 * Get tokens nested in the provided token
1218 * @param collectionId ID of collection1239 * @param collectionId ID of collection
1219 * @param tokenId ID of token1240 * @param tokenId ID of token
1220 * @param blockHashAt 1241 * @param blockHashAt
1221 * @example getTokenChildren(10, 5);1242 * @example getTokenChildren(10, 5);
1222 * @returns tokens whose depth of nesting is <= 5 1243 * @returns tokens whose depth of nesting is <= 5
1223 */1244 */
1224 async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {1245 async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {
1225 let children;1246 let children;
1226 if(typeof blockHashAt === 'undefined') {1247 if(typeof blockHashAt === 'undefined') {
1234 });1255 });
1235 }1256 }
12361257
1237 /**1258 /**
1238 * Nest one token into another1259 * Nest one token into another
1239 * @param signer keyring of signer1260 * @param signer keyring of signer
1240 * @param tokenObj token to be nested1261 * @param tokenObj token to be nested
1241 * @param rootTokenObj token to be parent1262 * @param rootTokenObj token to be parent
1242 * @param label 1263 * @param label
1243 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});1264 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});
1244 * @returns ```true``` if extrinsic success, otherwise ```false```1265 * @returns ```true``` if extrinsic success, otherwise ```false```
1245 */1266 */
1246 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, label='nest token'): Promise<boolean> {1267 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, label='nest token'): Promise<boolean> {
1247 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1268 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};
1248 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1269 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);
1252 return result;1273 return result;
1253 }1274 }
12541275
1255 /**1276 /**
1256 * Remove token from nested state1277 * Remove token from nested state
1257 * @param signer keyring of signer1278 * @param signer keyring of signer
1258 * @param tokenObj token to unnest1279 * @param tokenObj token to unnest
1259 * @param rootTokenObj parent of a token1280 * @param rootTokenObj parent of a token
1260 * @param toAddressObj address of a new token owner 1281 * @param toAddressObj address of a new token owner
1261 * @param label 1282 * @param label
1262 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});1283 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});
1263 * @returns ```true``` if extrinsic success, otherwise ```false```1284 * @returns ```true``` if extrinsic success, otherwise ```false```
1264 */1285 */
1265 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId, label='unnest token'): Promise<boolean> {1286 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId, label='unnest token'): Promise<boolean> {
1266 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1287 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};
1267 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1288 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);
1271 return result;1292 return result;
1272 }1293 }
12731294
1274 /**1295 /**
1275 * Mint new collection1296 * Mint new collection
1276 * @param signer keyring of signer1297 * @param signer keyring of signer
1277 * @param collectionOptions Collection options1298 * @param collectionOptions Collection options
1278 * @param label 1299 * @param label
1279 * @example 1300 * @example
1280 * mintCollection(aliceKeyring, {1301 * mintCollection(aliceKeyring, {
1281 * name: 'New',1302 * name: 'New',
1282 * description: 'New collection',1303 * description: 'New collection',
1283 * tokenPrefix: 'NEW',1304 * tokenPrefix: 'NEW',
1284 * })1305 * })
1285 * @returns object of the created collection1306 * @returns object of the created collection
1286 */1307 */
1287 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueNFTCollection> {1308 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueNFTCollection> {
1288 return await super.mintCollection(signer, collectionOptions, 'NFT', `Unable to mint NFT collection for ${label}`) as UniqueNFTCollection;1309 return await super.mintCollection(signer, collectionOptions, 'NFT', `Unable to mint NFT collection for ${label}`) as UniqueNFTCollection;
1289 }1310 }
12901311
1291 /**1312 /**
1292 * Mint new token1313 * Mint new token
1293 * @param signer keyring of signer1314 * @param signer keyring of signer
1294 * @param data token data1315 * @param data token data
1295 * @param label 1316 * @param label
1296 * @returns created token object1317 * @returns created token object
1297 */1318 */
1298 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }, label?: string): Promise<UniqueNFTToken> {1319 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }, label?: string): Promise<UniqueNFTToken> {
1299 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;1320 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;
1300 const creationResult = await this.helper.executeExtrinsic(1321 const creationResult = await this.helper.executeExtrinsic(
1312 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1333 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);
1313 }1334 }
13141335
1315 /**1336 /**
1316 * Mint multiple NFT tokens1337 * Mint multiple NFT tokens
1317 * @param signer keyring of signer1338 * @param signer keyring of signer
1318 * @param collectionId ID of collection1339 * @param collectionId ID of collection
1319 * @param tokens array of tokens with owner and properties1340 * @param tokens array of tokens with owner and properties
1320 * @param label 1341 * @param label
1321 * @example 1342 * @example
1322 * mintMultipleTokens(aliceKeyring, 10, [{1343 * mintMultipleTokens(aliceKeyring, 10, [{
1323 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},1344 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},
1324 * properties: [{key: "gender", value: "male"},{key: "age", value: "45"}],1345 * properties: [{key: "gender", value: "male"},{key: "age", value: "45"}],
1325 * },{1346 * },{
1326 * owner: {Ethereum: "0x9F0583DbB855d..."},1347 * owner: {Ethereum: "0x9F0583DbB855d..."},
1327 * properties: [{key: "gender", value: "female"},{key: "age", value: "22"}],1348 * properties: [{key: "gender", value: "female"},{key: "age", value: "22"}],
1328 * }]);1349 * }]);
1329 * @returns ```true``` if extrinsic success, otherwise ```false```1350 * @returns ```true``` if extrinsic success, otherwise ```false```
1330 */1351 */
1331 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1352 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {
1332 if(typeof label === 'undefined') label = `collection #${collectionId}`;1353 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1333 const creationResult = await this.helper.executeExtrinsic(1354 const creationResult = await this.helper.executeExtrinsic(
1339 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1360 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1340 }1361 }
13411362
1342 /**1363 /**
1343 * Mint multiple NFT tokens with one owner1364 * Mint multiple NFT tokens with one owner
1344 * @param signer keyring of signer1365 * @param signer keyring of signer
1345 * @param collectionId ID of collection1366 * @param collectionId ID of collection
1346 * @param owner tokens owner1367 * @param owner tokens owner
1347 * @param tokens array of tokens with owner and properties1368 * @param tokens array of tokens with owner and properties
1348 * @param label 1369 * @param label
1349 * @example1370 * @example
1350 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{1371 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{
1351 * properties: [{1372 * properties: [{
1352 * key: "gender",1373 * key: "gender",
1353 * value: "female",1374 * value: "female",
1354 * },{1375 * },{
1355 * key: "age",1376 * key: "age",
1356 * value: "33",1377 * value: "33",
1357 * }],1378 * }],
1358 * }]);1379 * }]);
1359 * @returns array of newly created tokens1380 * @returns array of newly created tokens
1360 */1381 */
1361 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1382 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {
1362 if(typeof label === 'undefined') label = `collection #${collectionId}`;1383 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1363 const rawTokens = [];1384 const rawTokens = [];
1374 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1395 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1375 }1396 }
13761397
1377 /**1398 /**
1378 * Destroys a concrete instance of NFT.1399 * Destroys a concrete instance of NFT.
1379 * @param signer keyring of signer1400 * @param signer keyring of signer
1380 * @param collectionId ID of collection1401 * @param collectionId ID of collection
1381 * @param tokenId ID of token1402 * @param tokenId ID of token
1382 * @param label 1403 * @param label
1383 * @example burnToken(aliceKeyring, 10, 5);1404 * @example burnToken(aliceKeyring, 10, 5);
1384 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1405 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
1385 */1406 */
1386 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string): Promise<{ success: boolean; token: number | null; }> {1407 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string): Promise<{ success: boolean; token: number | null; }> {
1387 return await super.burnToken(signer, collectionId, tokenId, label, 1n);1408 return await super.burnToken(signer, collectionId, tokenId, label, 1n);
1388 }1409 }
13891410
1390 /**1411 /**
1391 * Set, change, or remove approved address to transfer the ownership of the NFT.1412 * Set, change, or remove approved address to transfer the ownership of the NFT.
1392 * 1413 *
1393 * @param signer keyring of signer1414 * @param signer keyring of signer
1394 * @param collectionId ID of collection1415 * @param collectionId ID of collection
1395 * @param tokenId ID of token1416 * @param tokenId ID of token
1396 * @param toAddressObj address to approve1417 * @param toAddressObj address to approve
1397 * @param label 1418 * @param label
1398 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1419 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})
1399 * @returns ```true``` if extrinsic success, otherwise ```false```1420 * @returns ```true``` if extrinsic success, otherwise ```false```
1400 */1421 */
1401 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {1422 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {
1402 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, 1n);1423 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, 1n);
1403 }1424 }
1426 return new UniqueRFTToken(tokenId, this.getCollectionObject(collectionId));1447 return new UniqueRFTToken(tokenId, this.getCollectionObject(collectionId));
1427 }1448 }
14281449
1429 /**1450 /**
1430 * Get top 10 token owners with the largest number of pieces 1451 * Get top 10 token owners with the largest number of pieces
1431 * @param collectionId ID of collection1452 * @param collectionId ID of collection
1432 * @param tokenId ID of token1453 * @param tokenId ID of token
1433 * @example getTokenTop10Owners(10, 5);1454 * @example getTokenTop10Owners(10, 5);
1434 * @returns array of top 10 owners1455 * @returns array of top 10 owners
1435 */1456 */
1436 async getTokenTop10Owners(collectionId: number, tokenId: number): Promise<ICrossAccountId[]> {1457 async getTokenTop10Owners(collectionId: number, tokenId: number): Promise<ICrossAccountId[]> {
1437 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, tokenId])).toJSON().map(crossAccountIdFromLower);1458 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, tokenId])).toJSON().map(crossAccountIdFromLower);
1438 }1459 }
1463 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);1484 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);
1464 }1485 }
14651486
1466 /**1487 /**
1467 * Change ownership of some pieces of RFT on behalf of the owner. 1488 * Change ownership of some pieces of RFT on behalf of the owner.
1468 * @param signer keyring of signer1489 * @param signer keyring of signer
1469 * @param collectionId ID of collection1490 * @param collectionId ID of collection
1470 * @param tokenId ID of token1491 * @param tokenId ID of token
1471 * @param fromAddressObj address on behalf of which the token will be sent1492 * @param fromAddressObj address on behalf of which the token will be sent
1472 * @param toAddressObj new token owner1493 * @param toAddressObj new token owner
1473 * @param amount number of pieces to be transfered1494 * @param amount number of pieces to be transfered
1474 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)1495 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)
1475 * @returns ```true``` if extrinsic success, otherwise ```false```1496 * @returns ```true``` if extrinsic success, otherwise ```false```
1476 */1497 */
1477 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n): Promise<boolean> {1498 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n): Promise<boolean> {
1478 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);1499 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);
1479 }1500 }
14801501
1481 /**1502 /**
1482 * Mint new collection1503 * Mint new collection
1483 * @param signer keyring of signer1504 * @param signer keyring of signer
1484 * @param collectionOptions Collection options1505 * @param collectionOptions Collection options
1485 * @param label 1506 * @param label
1486 * @example1507 * @example
1487 * mintCollection(aliceKeyring, {1508 * mintCollection(aliceKeyring, {
1488 * name: 'New',1509 * name: 'New',
1489 * description: 'New collection',1510 * description: 'New collection',
1490 * tokenPrefix: 'NEW',1511 * tokenPrefix: 'NEW',
1491 * })1512 * })
1492 * @returns object of the created collection1513 * @returns object of the created collection
1493 */1514 */
1494 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueRFTCollection> {1515 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueRFTCollection> {
1495 return await super.mintCollection(signer, collectionOptions, 'RFT', `Unable to mint RFT collection for ${label}`) as UniqueRFTCollection;1516 return await super.mintCollection(signer, collectionOptions, 'RFT', `Unable to mint RFT collection for ${label}`) as UniqueRFTCollection;
1496 }1517 }
14971518
1498 /**1519 /**
1499 * Mint new token1520 * Mint new token
1500 * @param signer keyring of signer1521 * @param signer keyring of signer
1501 * @param data token data1522 * @param data token data
1502 * @param label 1523 * @param label
1503 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});1524 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});
1504 * @returns created token object1525 * @returns created token object
1505 */1526 */
1506 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }, label?: string): Promise<UniqueRFTToken> {1527 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }, label?: string): Promise<UniqueRFTToken> {
1507 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;1528 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;
1508 const creationResult = await this.helper.executeExtrinsic(1529 const creationResult = await this.helper.executeExtrinsic(
1533 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1554 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1534 }1555 }
15351556
1536 /**1557 /**
1537 * Mint multiple RFT tokens with one owner1558 * Mint multiple RFT tokens with one owner
1538 * @param signer keyring of signer1559 * @param signer keyring of signer
1539 * @param collectionId ID of collection1560 * @param collectionId ID of collection
1540 * @param owner tokens owner1561 * @param owner tokens owner
1541 * @param tokens array of tokens with properties and pieces1562 * @param tokens array of tokens with properties and pieces
1542 * @param label 1563 * @param label
1543 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);1564 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);
1544 * @returns array of newly created RFT tokens1565 * @returns array of newly created RFT tokens
1545 */1566 */
1546 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {1567 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {
1547 if(typeof label === 'undefined') label = `collection #${collectionId}`;1568 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1548 const rawTokens = [];1569 const rawTokens = [];
1559 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1580 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1560 }1581 }
15611582
1562 /**1583 /**
1563 * Destroys a concrete instance of RFT.1584 * Destroys a concrete instance of RFT.
1564 * @param signer keyring of signer1585 * @param signer keyring of signer
1565 * @param collectionId ID of collection1586 * @param collectionId ID of collection
1566 * @param tokenId ID of token1587 * @param tokenId ID of token
1567 * @param label 1588 * @param label
1568 * @param amount number of pieces to be burnt1589 * @param amount number of pieces to be burnt
1569 * @example burnToken(aliceKeyring, 10, 5);1590 * @example burnToken(aliceKeyring, 10, 5);
1570 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1591 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
1571 */1592 */
1572 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string, amount=100n): Promise<{ success: boolean; token: number | null; }> {1593 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string, amount=100n): Promise<{ success: boolean; token: number | null; }> {
1573 return await super.burnToken(signer, collectionId, tokenId, label, amount);1594 return await super.burnToken(signer, collectionId, tokenId, label, amount);
1574 }1595 }
15751596
1576 /**1597 /**
1577 * Set, change, or remove approved address to transfer the ownership of the RFT.1598 * Set, change, or remove approved address to transfer the ownership of the RFT.
1578 * 1599 *
1579 * @param signer keyring of signer1600 * @param signer keyring of signer
1580 * @param collectionId ID of collection1601 * @param collectionId ID of collection
1581 * @param tokenId ID of token1602 * @param tokenId ID of token
1582 * @param toAddressObj address to approve1603 * @param toAddressObj address to approve
1583 * @param label 1604 * @param label
1584 * @param amount number of pieces to be approved1605 * @param amount number of pieces to be approved
1585 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);1606 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);
1586 * @returns true if the token success, otherwise false1607 * @returns true if the token success, otherwise false
1587 */1608 */
1588 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=100n) {1609 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=100n) {
1589 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, amount);1610 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, amount);
1590 }1611 }
1600 return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, tokenId])).unwrap().toBigInt();1621 return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, tokenId])).unwrap().toBigInt();
1601 }1622 }
16021623
1603 /**1624 /**
1604 * Change number of token pieces. Signer must be the owner of all token pieces.1625 * Change number of token pieces. Signer must be the owner of all token pieces.
1605 * @param signer keyring of signer1626 * @param signer keyring of signer
1606 * @param collectionId ID of collection1627 * @param collectionId ID of collection
1607 * @param tokenId ID of token1628 * @param tokenId ID of token
1608 * @param amount new number of pieces1629 * @param amount new number of pieces
1609 * @param label 1630 * @param label
1610 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);1631 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);
1611 * @returns true if the repartion was success, otherwise false1632 * @returns true if the repartion was success, otherwise false
1612 */1633 */
1613 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint, label?: string): Promise<boolean> {1634 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint, label?: string): Promise<boolean> {
1614 if(typeof label === 'undefined') label = `collection #${collectionId}`;1635 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1615 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);1636 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);
1635 return new UniqueFTCollection(collectionId, this.helper);1656 return new UniqueFTCollection(collectionId, this.helper);
1636 }1657 }
16371658
1638 /**1659 /**
1639 * Mint new fungible collection1660 * Mint new fungible collection
1640 * @param signer keyring of signer1661 * @param signer keyring of signer
1641 * @param collectionOptions Collection options1662 * @param collectionOptions Collection options
1642 * @param decimalPoints number of token decimals 1663 * @param decimalPoints number of token decimals
1643 * @param errorLabel 1664 * @param errorLabel
1644 * @example1665 * @example
1645 * mintCollection(aliceKeyring, {1666 * mintCollection(aliceKeyring, {
1646 * name: 'New',1667 * name: 'New',
1647 * description: 'New collection',1668 * description: 'New collection',
1648 * tokenPrefix: 'NEW',1669 * tokenPrefix: 'NEW',
1649 * }, 18)1670 * }, 18)
1650 * @returns newly created fungible collection1671 * @returns newly created fungible collection
1651 */1672 */
1652 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0, errorLabel = 'Unable to mint collection'): Promise<UniqueFTCollection> {1673 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0, errorLabel = 'Unable to mint collection'): Promise<UniqueFTCollection> {
1653 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1674 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object
1654 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');1675 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');
1664 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));1685 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));
1665 }1686 }
16661687
1667 /**1688 /**
1668 * Mint tokens1689 * Mint tokens
1669 * @param signer keyring of signer1690 * @param signer keyring of signer
1670 * @param collectionId ID of collection1691 * @param collectionId ID of collection
1671 * @param owner address owner of new tokens1692 * @param owner address owner of new tokens
1672 * @param amount amount of tokens to be meanted1693 * @param amount amount of tokens to be meanted
1673 * @param label 1694 * @param label
1674 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1695 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);
1675 * @returns ```true``` if extrinsic success, otherwise ```false``` 1696 * @returns ```true``` if extrinsic success, otherwise ```false```
1676 */1697 */
1677 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint, label?: string): Promise<boolean> {1698 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint, label?: string): Promise<boolean> {
1678 if(typeof label === 'undefined') label = `collection #${collectionId}`;1699 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1679 const creationResult = await this.helper.executeExtrinsic(1700 const creationResult = await this.helper.executeExtrinsic(
1688 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1709 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);
1689 }1710 }
16901711
1691 /**1712 /**
1692 * Mint multiple Fungible tokens with one owner1713 * Mint multiple Fungible tokens with one owner
1693 * @param signer keyring of signer1714 * @param signer keyring of signer
1694 * @param collectionId ID of collection1715 * @param collectionId ID of collection
1695 * @param owner tokens owner1716 * @param owner tokens owner
1696 * @param tokens array of tokens with properties and pieces1717 * @param tokens array of tokens with properties and pieces
1697 * @param label 1718 * @param label
1698 * @returns ```true``` if extrinsic success, otherwise ```false``` 1719 * @returns ```true``` if extrinsic success, otherwise ```false```
1699 */1720 */
1700 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string): Promise<boolean> {1721 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string): Promise<boolean> {
1701 if(typeof label === 'undefined') label = `collection #${collectionId}`;1722 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1702 const rawTokens = [];1723 const rawTokens = [];
1712 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1733 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);
1713 }1734 }
17141735
1715 /**1736 /**
1716 * Get the top 10 owners with the largest balance for the Fungible collection 1737 * Get the top 10 owners with the largest balance for the Fungible collection
1717 * @param collectionId ID of collection1738 * @param collectionId ID of collection
1718 * @example getTop10Owners(10);1739 * @example getTop10Owners(10);
1719 * @returns array of ```ICrossAccountId```1740 * @returns array of ```ICrossAccountId```
1720 */1741 */
1721 async getTop10Owners(collectionId: number): Promise<ICrossAccountId[]> {1742 async getTop10Owners(collectionId: number): Promise<ICrossAccountId[]> {
1722 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, 0])).toJSON().map(crossAccountIdFromLower);1743 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, 0])).toJSON().map(crossAccountIdFromLower);
1723 }1744 }
1733 return (await this.helper.callRpc('api.rpc.unique.balance', [collectionId, addressObj, 0])).toBigInt();1754 return (await this.helper.callRpc('api.rpc.unique.balance', [collectionId, addressObj, 0])).toBigInt();
1734 }1755 }
17351756
1736 /**1757 /**
1737 * Transfer tokens to address1758 * Transfer tokens to address
1738 * @param signer keyring of signer1759 * @param signer keyring of signer
1739 * @param collectionId ID of collection1760 * @param collectionId ID of collection
1740 * @param toAddressObj address recepient1761 * @param toAddressObj address recepient
1741 * @param amount amount of tokens to be sent1762 * @param amount amount of tokens to be sent
1742 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1763 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
1743 * @returns ```true``` if extrinsic success, otherwise ```false``` 1764 * @returns ```true``` if extrinsic success, otherwise ```false```
1744 */1765 */
1745 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount: bigint) {1766 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount: bigint) {
1746 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1767 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);
1747 }1768 }
17481769
1749 /**1770 /**
1750 * Transfer some tokens on behalf of the owner.1771 * Transfer some tokens on behalf of the owner.
1751 * @param signer keyring of signer1772 * @param signer keyring of signer
1752 * @param collectionId ID of collection1773 * @param collectionId ID of collection
1753 * @param fromAddressObj address on behalf of which tokens will be sent1774 * @param fromAddressObj address on behalf of which tokens will be sent
1754 * @param toAddressObj address where token to be sent1775 * @param toAddressObj address where token to be sent
1755 * @param amount number of tokens to be sent1776 * @param amount number of tokens to be sent
1756 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);1777 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);
1757 * @returns ```true``` if extrinsic success, otherwise ```false``` 1778 * @returns ```true``` if extrinsic success, otherwise ```false```
1758 */1779 */
1759 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {1780 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {
1760 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);1781 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);
1761 }1782 }
17621783
1763 /**1784 /**
1764 * Destroy some amount of tokens1785 * Destroy some amount of tokens
1765 * @param signer keyring of signer1786 * @param signer keyring of signer
1766 * @param collectionId ID of collection1787 * @param collectionId ID of collection
1767 * @param amount amount of tokens to be destroyed1788 * @param amount amount of tokens to be destroyed
1768 * @param label 1789 * @param label
1769 * @example burnTokens(aliceKeyring, 10, 1000n);1790 * @example burnTokens(aliceKeyring, 10, 1000n);
1770 * @returns ```true``` if extrinsic success, otherwise ```false``` 1791 * @returns ```true``` if extrinsic success, otherwise ```false```
1771 */1792 */
1772 async burnTokens(signer: IKeyringPair, collectionId: number, amount=100n, label?: string): Promise<boolean> {1793 async burnTokens(signer: IKeyringPair, collectionId: number, amount=100n, label?: string): Promise<boolean> {
1773 return (await super.burnToken(signer, collectionId, 0, label, amount)).success;1794 return (await super.burnToken(signer, collectionId, 0, label, amount)).success;
1774 }1795 }
17751796
1776 /**1797 /**
1777 * Burn some tokens on behalf of the owner.1798 * Burn some tokens on behalf of the owner.
1778 * @param signer keyring of signer1799 * @param signer keyring of signer
1779 * @param collectionId ID of collection1800 * @param collectionId ID of collection
1780 * @param fromAddressObj address on behalf of which tokens will be burnt1801 * @param fromAddressObj address on behalf of which tokens will be burnt
1781 * @param amount amount of tokens to be burnt1802 * @param amount amount of tokens to be burnt
1782 * @param label 1803 * @param label
1783 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1804 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
1784 * @returns ```true``` if extrinsic success, otherwise ```false``` 1805 * @returns ```true``` if extrinsic success, otherwise ```false```
1785 */1806 */
1786 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=100n, label?: string): Promise<boolean> {1807 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=100n, label?: string): Promise<boolean> {
1787 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, label, amount);1808 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, label, amount);
1788 }1809 }
17891810
1790 /**1811 /**
1791 * Get total collection supply1812 * Get total collection supply
1792 * @param collectionId 1813 * @param collectionId
1793 * @returns 1814 * @returns
1794 */1815 */
1795 async getTotalPieces(collectionId: number): Promise<bigint> {1816 async getTotalPieces(collectionId: number): Promise<bigint> {
1796 return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, 0])).unwrap().toBigInt();1817 return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, 0])).unwrap().toBigInt();
1797 }1818 }
17981819
1799 /**1820 /**
1800 * Set, change, or remove approved address to transfer tokens.1821 * Set, change, or remove approved address to transfer tokens.
1801 * 1822 *
1802 * @param signer keyring of signer1823 * @param signer keyring of signer
1803 * @param collectionId ID of collection1824 * @param collectionId ID of collection
1804 * @param toAddressObj address to be approved1825 * @param toAddressObj address to be approved
1805 * @param amount amount of tokens to be approved1826 * @param amount amount of tokens to be approved
1806 * @param label 1827 * @param label
1807 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)1828 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)
1808 * @returns ```true``` if extrinsic success, otherwise ```false``` 1829 * @returns ```true``` if extrinsic success, otherwise ```false```
1809 */1830 */
1810 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {1831 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {
1811 return super.approveToken(signer, collectionId, 0, toAddressObj, label, amount);1832 return super.approveToken(signer, collectionId, 0, toAddressObj, label, amount);
1812 }1833 }
2059 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj, label);2080 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj, label);
2060 }2081 }
2082
2083 async removeFromAllowList(signer: TSigner, addressObj: ICrossAccountId, label?: string) {
2084 return await this.helper.collection.removeFromAllowList(signer, this.collectionId, addressObj, label);
2085 }
20612086
2062 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {2087 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {
2063 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj, label);2088 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj, label);