difftreelog
Merge branch 'develop' into tests/eth-playgrounds
in: master
3 files changed
tests/src/util/playgrounds/index.tsdiffbeforeafterbothno syntactic changes
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth149 let accountsCreated = false;149 let accountsCreated = false;150 // checkBalances retry up to 5 blocks150 // checkBalances retry up to 5 blocks151 for (let index = 0; index < 5; index++) {151 for (let index = 0; index < 5; index++) {152 console.log(await this.helper.chain.getLatestBlockNumber());153 accountsCreated = await checkBalances();152 accountsCreated = await checkBalances();154 if(accountsCreated) break;153 if(accountsCreated) break;155 await this.waitNewBlocks(1);154 await this.waitNewBlocks(1);tests/src/util/playgrounds/unique.tsdiffbeforeafterboth91 return encodeAddress(decodeAddress(address), ss58Format);91 return encodeAddress(decodeAddress(address), ss58Format);92 }92 }939394 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult, label = 'new collection') {94 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult) {95 if (creationResult.status !== this.transactionStatus.SUCCESS) {95 if (creationResult.status !== this.transactionStatus.SUCCESS) {96 throw Error(`Unable to create collection for ${label}`);96 throw Error('Unable to create collection!');97 }97 }989899 let collectionId = null;99 let collectionId = null;104 });104 });105105106 if (collectionId === null) {106 if (collectionId === null) {107 throw Error(`No CollectionCreated event for ${label}`);107 throw Error('No CollectionCreated event was found!');108 }108 }109109110 return collectionId;110 return collectionId;111 }111 }112112113 static extractTokensFromCreationResult(creationResult: ITransactionResult, label = 'new tokens') {113 static extractTokensFromCreationResult(creationResult: ITransactionResult) {114 if (creationResult.status !== this.transactionStatus.SUCCESS) {114 if (creationResult.status !== this.transactionStatus.SUCCESS) {115 throw Error(`Unable to create tokens for ${label}`);115 throw Error('Unable to create tokens!');116 }116 }117 let success = false;117 let success = false;118 const tokens = [] as any;118 const tokens = [] as any;130 return {success, tokens};130 return {success, tokens};131 }131 }132132133 static extractTokensFromBurnResult(burnResult: ITransactionResult, label = 'burned tokens') {133 static extractTokensFromBurnResult(burnResult: ITransactionResult) {134 if (burnResult.status !== this.transactionStatus.SUCCESS) {134 if (burnResult.status !== this.transactionStatus.SUCCESS) {135 throw Error(`Unable to burn tokens for ${label}`);135 throw Error('Unable to burn tokens!');136 }136 }137 let success = false;137 let success = false;138 const tokens = [] as any;138 const tokens = [] as any;150 return {success, tokens};150 return {success, tokens};151 }151 }152152153 static findCollectionInEvents(events: {event: IChainEvent}[], collectionId: number, expectedSection: string, expectedMethod: string, label?: string) {153 static findCollectionInEvents(events: {event: IChainEvent}[], collectionId: number, expectedSection: string, expectedMethod: string) {154 let eventId = null;154 let eventId = null;155 events.forEach(({event: {data, method, section}}) => {155 events.forEach(({event: {data, method, section}}) => {156 if ((section === expectedSection) && (method === expectedMethod)) {156 if ((section === expectedSection) && (method === expectedMethod)) {159 });159 });160160161 if (eventId === null) {161 if (eventId === null) {162 throw Error(`No ${expectedMethod} event for ${label}`);162 throw Error(`No ${expectedMethod} event was found!`);163 }163 }164 return eventId === collectionId;164 return eventId === collectionId;165 }165 }365 return call(...params);365 return call(...params);366 }366 }367367368 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=false, failureMessage='expected success') {368 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=false/*, failureMessage='expected success'*/) {369 if(this.api === null) throw Error('API not initialized');369 if(this.api === null) throw Error('API not initialized');370 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);370 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);371371398398399 this.chainLog.push(log);399 this.chainLog.push(log);400400401 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) throw Error(failureMessage);401 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) throw Error(`${result.moduleError}`);402 return result;402 return result;403 }403 }404404558 * 558 * 559 * @param signer keyring of signer559 * @param signer keyring of signer560 * @param collectionId ID of collection560 * @param collectionId ID of collection561 * @param label extra label for log562 * @example await helper.collection.burn(aliceKeyring, 3);561 * @example await helper.collection.burn(aliceKeyring, 3);563 * @returns ```true``` if extrinsic success, otherwise ```false```562 * @returns ```true``` if extrinsic success, otherwise ```false```564 */563 */565 async burn(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {564 async burn(signer: TSigner, collectionId: number): Promise<boolean> {566 if(typeof label === 'undefined') label = `collection #${collectionId}`;567 const result = await this.helper.executeExtrinsic(565 const result = await this.helper.executeExtrinsic(568 signer,566 signer,569 'api.tx.unique.destroyCollection', [collectionId],567 'api.tx.unique.destroyCollection', [collectionId],570 true, `Unable to burn collection for ${label}`,568 true,571 );569 );572570573 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed', label);571 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed');574 }572 }575573576 /**574 /**579 * @param signer keyring of signer577 * @param signer keyring of signer580 * @param collectionId ID of collection578 * @param collectionId ID of collection581 * @param sponsorAddress Sponsor substrate address579 * @param sponsorAddress Sponsor substrate address582 * @param label extra label for log583 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")580 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")584 * @returns ```true``` if extrinsic success, otherwise ```false```581 * @returns ```true``` if extrinsic success, otherwise ```false```585 */582 */586 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount, label?: string): Promise<boolean> {583 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount): Promise<boolean> {587 if(typeof label === 'undefined') label = `collection #${collectionId}`;588 const result = await this.helper.executeExtrinsic(584 const result = await this.helper.executeExtrinsic(589 signer,585 signer,590 'api.tx.unique.setCollectionSponsor', [collectionId, sponsorAddress],586 'api.tx.unique.setCollectionSponsor', [collectionId, sponsorAddress],591 true, `Unable to set collection sponsor for ${label}`,587 true,592 );588 );593589594 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet', label);590 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet');595 }591 }596592597 /**593 /**598 * Confirms consent to sponsor the collection on behalf of the signer.594 * Confirms consent to sponsor the collection on behalf of the signer.599 * 595 * 600 * @param signer keyring of signer596 * @param signer keyring of signer601 * @param collectionId ID of collection597 * @param collectionId ID of collection602 * @param label extra label for log603 * @example confirmSponsorship(aliceKeyring, 10)598 * @example confirmSponsorship(aliceKeyring, 10)604 * @returns ```true``` if extrinsic success, otherwise ```false```599 * @returns ```true``` if extrinsic success, otherwise ```false```605 */600 */606 async confirmSponsorship(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {601 async confirmSponsorship(signer: TSigner, collectionId: number): Promise<boolean> {607 if(typeof label === 'undefined') label = `collection #${collectionId}`;608 const result = await this.helper.executeExtrinsic(602 const result = await this.helper.executeExtrinsic(609 signer,603 signer,610 'api.tx.unique.confirmSponsorship', [collectionId],604 'api.tx.unique.confirmSponsorship', [collectionId],611 true, `Unable to confirm collection sponsorship for ${label}`,605 true,612 );606 );613607614 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed', label);608 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed');615 }609 }616610617 /**611 /**620 * @param signer keyring of signer614 * @param signer keyring of signer621 * @param collectionId ID of collection615 * @param collectionId ID of collection622 * @param limits collection limits object616 * @param limits collection limits object623 * @param label extra label for log624 * @example617 * @example625 * await setLimits(618 * await setLimits(626 * aliceKeyring,619 * aliceKeyring,632 * )625 * )633 * @returns ```true``` if extrinsic success, otherwise ```false```626 * @returns ```true``` if extrinsic success, otherwise ```false```634 */627 */635 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits, label?: string): Promise<boolean> {628 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits): Promise<boolean> {636 if(typeof label === 'undefined') label = `collection #${collectionId}`;637 const result = await this.helper.executeExtrinsic(629 const result = await this.helper.executeExtrinsic(638 signer,630 signer,639 'api.tx.unique.setCollectionLimits', [collectionId, limits],631 'api.tx.unique.setCollectionLimits', [collectionId, limits],640 true, `Unable to set collection limits for ${label}`,632 true,641 );633 );642634643 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet', label);635 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet');644 }636 }645637646 /**638 /**649 * @param signer keyring of signer641 * @param signer keyring of signer650 * @param collectionId ID of collection642 * @param collectionId ID of collection651 * @param ownerAddress substrate address of new owner643 * @param ownerAddress substrate address of new owner652 * @param label extra label for log653 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")644 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")654 * @returns ```true``` if extrinsic success, otherwise ```false```645 * @returns ```true``` if extrinsic success, otherwise ```false```655 */646 */656 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount, label?: string): Promise<boolean> {647 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount): Promise<boolean> {657 if(typeof label === 'undefined') label = `collection #${collectionId}`;658 const result = await this.helper.executeExtrinsic(648 const result = await this.helper.executeExtrinsic(659 signer,649 signer,660 'api.tx.unique.changeCollectionOwner', [collectionId, ownerAddress],650 'api.tx.unique.changeCollectionOwner', [collectionId, ownerAddress],661 true, `Unable to change collection owner for ${label}`,651 true,662 );652 );663653664 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged', label);654 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged');665 }655 }666656667 /**657 /**670 * @param signer keyring of signer660 * @param signer keyring of signer671 * @param collectionId ID of collection661 * @param collectionId ID of collection672 * @param adminAddressObj Administrator address (substrate or ethereum)662 * @param adminAddressObj Administrator address (substrate or ethereum)673 * @param label extra label for log674 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})663 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})675 * @returns ```true``` if extrinsic success, otherwise ```false```664 * @returns ```true``` if extrinsic success, otherwise ```false```676 */665 */677 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {666 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId): Promise<boolean> {678 if(typeof label === 'undefined') label = `collection #${collectionId}`;679 const result = await this.helper.executeExtrinsic(667 const result = await this.helper.executeExtrinsic(680 signer,668 signer,681 'api.tx.unique.addCollectionAdmin', [collectionId, adminAddressObj],669 'api.tx.unique.addCollectionAdmin', [collectionId, adminAddressObj],682 true, `Unable to add collection admin for ${label}`,670 true,683 );671 );684672685 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded', label);673 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded');686 }674 }687675688 /**676 /**677 * Removes a collection administrator.678 * 679 * @param signer keyring of signer680 * @param collectionId ID of collection681 * @param adminAddressObj Administrator address (substrate or ethereum)682 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})683 * @returns ```true``` if extrinsic success, otherwise ```false```684 */685 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId): Promise<boolean> {686 const result = await this.helper.executeExtrinsic(687 signer,688 'api.tx.unique.removeCollectionAdmin', [collectionId, adminAddressObj],689 true,690 );691692 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved');693 }694695 /**689 * Adds an address to allow list 696 * Adds an address to allow list 690 * @param signer keyring of signer697 * @param signer keyring of signer691 * @param collectionId ID of collection698 * @param collectionId ID of collection692 * @param addressObj address to add to the allow list699 * @param addressObj address to add to the allow list693 * @param label extra label for log694 * @returns ```true``` if extrinsic success, otherwise ```false```700 * @returns ```true``` if extrinsic success, otherwise ```false```695 */701 */696 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId, label?: string): Promise<boolean> {702 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId): Promise<boolean> {697 if(typeof label === 'undefined') label = `collection #${collectionId}`;698 const result = await this.helper.executeExtrinsic(703 const result = await this.helper.executeExtrinsic(699 signer,704 signer,700 'api.tx.unique.addToAllowList', [collectionId, addressObj],705 'api.tx.unique.addToAllowList', [collectionId, addressObj],701 true, `Unable to add address to allow list for ${label}`,706 true,702 );707 );703708704 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');709 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');705 }710 }706711707 /**712 /**708 * Removes a collection administrator.713 * Removes an address from allow list 709 * 714 * 710 * @param signer keyring of signer715 * @param signer keyring of signer711 * @param collectionId ID of collection716 * @param collectionId ID of collection712 * @param adminAddressObj Administrator address (substrate or ethereum)717 * @param addressObj address to remove from the allow list713 * @param label extra label for log714 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})715 * @returns ```true``` if extrinsic success, otherwise ```false```718 * @returns ```true``` if extrinsic success, otherwise ```false```716 */719 */717 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {720 async removeFromAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId): Promise<boolean> {718 if(typeof label === 'undefined') label = `collection #${collectionId}`;719 const result = await this.helper.executeExtrinsic(721 const result = await this.helper.executeExtrinsic(720 signer,722 signer,721 'api.tx.unique.removeCollectionAdmin', [collectionId, adminAddressObj],723 'api.tx.unique.removeFromAllowList', [collectionId, addressObj],722 true, `Unable to remove collection admin for ${label}`,724 true,723 );725 );724726725 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved', label);727 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressRemoved');726 }728 }727729728 /**730 /**731 * @param signer keyring of signer733 * @param signer keyring of signer732 * @param collectionId ID of collection734 * @param collectionId ID of collection733 * @param permissions collection permissions object735 * @param permissions collection permissions object734 * @param label extra label for log735 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});736 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});736 * @returns ```true``` if extrinsic success, otherwise ```false```737 * @returns ```true``` if extrinsic success, otherwise ```false```737 */738 */738 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions, label?: string): Promise<boolean> {739 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions): Promise<boolean> {739 if(typeof label === 'undefined') label = `collection #${collectionId}`;740 const result = await this.helper.executeExtrinsic(740 const result = await this.helper.executeExtrinsic(741 signer,741 signer,742 'api.tx.unique.setCollectionPermissions', [collectionId, permissions],742 'api.tx.unique.setCollectionPermissions', [collectionId, permissions],743 true, `Unable to set collection permissions for ${label}`,743 true,744 );744 );745745746 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet', label);746 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet');747 }747 }748748749 /**749 /**752 * @param signer keyring of signer752 * @param signer keyring of signer753 * @param collectionId ID of collection753 * @param collectionId ID of collection754 * @param permissions nesting permissions object754 * @param permissions nesting permissions object755 * @param label extra label for log756 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});755 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});757 * @returns ```true``` if extrinsic success, otherwise ```false```756 * @returns ```true``` if extrinsic success, otherwise ```false```758 */757 */759 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions, label?: string): Promise<boolean> {758 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions): Promise<boolean> {760 return await this.setPermissions(signer, collectionId, {nesting: permissions}, label);759 return await this.setPermissions(signer, collectionId, {nesting: permissions});761 }760 }762761763 /**762 /**764 * Disables nesting for selected collection.763 * Disables nesting for selected collection.765 * 764 * 766 * @param signer keyring of signer765 * @param signer keyring of signer767 * @param collectionId ID of collection766 * @param collectionId ID of collection768 * @param label extra label for log769 * @example disableNesting(aliceKeyring, 10);767 * @example disableNesting(aliceKeyring, 10);770 * @returns ```true``` if extrinsic success, otherwise ```false```768 * @returns ```true``` if extrinsic success, otherwise ```false```771 */769 */772 async disableNesting(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {770 async disableNesting(signer: TSigner, collectionId: number): Promise<boolean> {773 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}}, label);771 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}});774 }772 }775773776 /**774 /**779 * @param signer keyring of signer777 * @param signer keyring of signer780 * @param collectionId ID of collection778 * @param collectionId ID of collection781 * @param properties array of property objects779 * @param properties array of property objects782 * @param label extra label for log783 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);780 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);784 * @returns ```true``` if extrinsic success, otherwise ```false```781 * @returns ```true``` if extrinsic success, otherwise ```false```785 */782 */786 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[], label?: string): Promise<boolean> {783 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[]): Promise<boolean> {787 if(typeof label === 'undefined') label = `collection #${collectionId}`;788 const result = await this.helper.executeExtrinsic(784 const result = await this.helper.executeExtrinsic(789 signer,785 signer,790 'api.tx.unique.setCollectionProperties', [collectionId, properties],786 'api.tx.unique.setCollectionProperties', [collectionId, properties],791 true, `Unable to set collection properties for ${label}`,787 true,792 );788 );793789794 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet', label);790 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet');795 }791 }796792797 /**793 /**800 * @param signer keyring of signer796 * @param signer keyring of signer801 * @param collectionId ID of collection797 * @param collectionId ID of collection802 * @param propertyKeys array of property keys to delete798 * @param propertyKeys array of property keys to delete803 * @param label804 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);799 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);805 * @returns ```true``` if extrinsic success, otherwise ```false```800 * @returns ```true``` if extrinsic success, otherwise ```false```806 */801 */807 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[], label?: string): Promise<boolean> {802 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[]): Promise<boolean> {808 if(typeof label === 'undefined') label = `collection #${collectionId}`;809 const result = await this.helper.executeExtrinsic(803 const result = await this.helper.executeExtrinsic(810 signer,804 signer,811 'api.tx.unique.deleteCollectionProperties', [collectionId, propertyKeys],805 'api.tx.unique.deleteCollectionProperties', [collectionId, propertyKeys],812 true, `Unable to delete collection properties for ${label}`,806 true,813 );807 );814808815 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted', label);809 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted');816 }810 }817811818 /**812 /**830 const result = await this.helper.executeExtrinsic(824 const result = await this.helper.executeExtrinsic(831 signer,825 signer,832 'api.tx.unique.transfer', [addressObj, collectionId, tokenId, amount],826 'api.tx.unique.transfer', [addressObj, collectionId, tokenId, amount],833 true, `Unable to transfer token #${tokenId} from collection #${collectionId}`,827 true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`,834 );828 );835829836 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);830 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);853 const result = await this.helper.executeExtrinsic(847 const result = await this.helper.executeExtrinsic(854 signer,848 signer,855 'api.tx.unique.transferFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],849 'api.tx.unique.transferFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],856 true, `Unable to transfer token #${tokenId} from collection #${collectionId}`,850 true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`,857 );851 );858 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);852 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);859 }853 }865 * @param signer keyring of signer859 * @param signer keyring of signer866 * @param collectionId ID of collection860 * @param collectionId ID of collection867 * @param tokenId ID of token861 * @param tokenId ID of token868 * @param label 869 * @param amount amount of tokens to be burned. For NFT must be set to 1n862 * @param amount amount of tokens to be burned. For NFT must be set to 1n870 * @example burnToken(aliceKeyring, 10, 5);863 * @example burnToken(aliceKeyring, 10, 5);871 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```864 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```872 */865 */873 async burnToken(signer: TSigner, collectionId: number, tokenId: number, label?: string, amount=1n): Promise<{866 async burnToken(signer: TSigner, collectionId: number, tokenId: number, amount=1n): Promise<{874 success: boolean,867 success: boolean,875 token: number | null868 token: number | null876 }> {869 }> {877 if(typeof label === 'undefined') label = `collection #${collectionId}`;878 const burnResult = await this.helper.executeExtrinsic(870 const burnResult = await this.helper.executeExtrinsic(879 signer,871 signer,880 'api.tx.unique.burnItem', [collectionId, tokenId, amount],872 'api.tx.unique.burnItem', [collectionId, tokenId, amount],881 true, `Unable to burn token for ${label}`,873 true, // `Unable to burn token for ${label}`,882 );874 );883 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult, label);875 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);884 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');876 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');885 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};877 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};886 }878 }892 * @param collectionId ID of collection884 * @param collectionId ID of collection893 * @param fromAddressObj address on behalf of which the token will be burnt885 * @param fromAddressObj address on behalf of which the token will be burnt894 * @param tokenId ID of token886 * @param tokenId ID of token895 * @param label 896 * @param amount amount of tokens to be burned. For NFT must be set to 1n887 * @param amount amount of tokens to be burned. For NFT must be set to 1n897 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})888 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})898 * @returns ```true``` if extrinsic success, otherwise ```false```889 * @returns ```true``` if extrinsic success, otherwise ```false```899 */890 */900 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, label?: string, amount=1n): Promise<boolean> {891 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, amount=1n): Promise<boolean> {901 if(typeof label === 'undefined') label = `collection #${collectionId}`;902 const burnResult = await this.helper.executeExtrinsic(892 const burnResult = await this.helper.executeExtrinsic(903 signer,893 signer,904 'api.tx.unique.burnFrom', [collectionId, fromAddressObj, tokenId, amount],894 'api.tx.unique.burnFrom', [collectionId, fromAddressObj, tokenId, amount],905 true, `Unable to burn token from for ${label}`,895 true, // `Unable to burn token from for ${label}`,906 );896 );907 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult, label);897 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);908 return burnedTokens.success && burnedTokens.tokens.length > 0;898 return burnedTokens.success && burnedTokens.tokens.length > 0;909 }899 }910900914 * @param signer keyring of signer904 * @param signer keyring of signer915 * @param collectionId ID of collection905 * @param collectionId ID of collection916 * @param tokenId ID of token906 * @param tokenId ID of token917 * @param toAddressObj 907 * @param toAddressObj Substrate or Ethereum address which gets approved use of the signer's tokens918 * @param label 919 * @param amount amount of token to be approved. For NFT must be set to 1n908 * @param amount amount of token to be approved. For NFT must be set to 1n920 * @returns ```true``` if extrinsic success, otherwise ```false```909 * @returns ```true``` if extrinsic success, otherwise ```false```921 */910 */922 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=1n) {911 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {923 if(typeof label === 'undefined') label = `collection #${collectionId}`;924 const approveResult = await this.helper.executeExtrinsic(912 const approveResult = await this.helper.executeExtrinsic(925 signer, 913 signer, 926 'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],914 'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],927 true, `Unable to approve token for ${label}`,915 true, // `Unable to approve token for ${label}`,928 );916 );929917930 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved', label);918 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved');931 }919 }932920933 /**921 /**934 * Get the amount of token pieces approved to transfer922 * Get the amount of token pieces approved to transfer or burn. Normally 0.923 * 935 * @param collectionId ID of collection924 * @param collectionId ID of collection936 * @param tokenId ID of token925 * @param tokenId ID of token937 * @param toAccountObj 926 * @param toAccountObj address which is approved to use token pieces938 * @param fromAccountObj927 * @param fromAccountObj address which may have allowed the use of its owned tokens939 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})928 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})940 * @returns number of approved to transfer pieces929 * @returns number of approved to transfer pieces941 */930 */944 }933 }945934946 /**935 /**947 * Get the last created token id936 * Get the last created token ID in a collection937 * 948 * @param collectionId ID of collection938 * @param collectionId ID of collection949 * @example getLastTokenId(10);939 * @example getLastTokenId(10);950 * @returns id of the last created token940 * @returns id of the last created token955945956 /**946 /**957 * Check if token exists947 * Check if token exists948 * 958 * @param collectionId ID of collection949 * @param collectionId ID of collection959 * @param tokenId ID of token950 * @param tokenId ID of token960 * @example isTokenExists(10, 20);951 * @example isTokenExists(10, 20);980971981 /**972 /**982 * Get token data973 * Get token data974 * 983 * @param collectionId ID of collection975 * @param collectionId ID of collection984 * @param tokenId ID of token976 * @param tokenId ID of token985 * @param blockHashAt 977 * @param propertyKeys optionally filter the token properties to only these keys986 * @param propertyKeys978 * @param blockHashAt optionally query the data at some block with this hash987 * @example getToken(10, 5);979 * @example getToken(10, 5);988 * @returns human readable token data 980 * @returns human readable token data 989 */981 */990 async getToken(collectionId: number, tokenId: number, blockHashAt?: string, propertyKeys?: string[]): Promise<{982 async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{991 properties: IProperty[];983 properties: IProperty[];992 owner: ICrossAccountId;984 owner: ICrossAccountId;993 normalizedOwner: ICrossAccountId;985 normalizedOwner: ICrossAccountId;997 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);989 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);998 }990 }999 else {991 else {1000 if(typeof propertyKeys === 'undefined') {992 if(propertyKeys.length == 0) {1001 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();993 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();1002 if(!collection) return null;994 if(!collection) return null;1003 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);995 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);101610081017 /**1009 /**1018 * Set permissions to change token properties1010 * Set permissions to change token properties1011 * 1019 * @param signer keyring of signer1012 * @param signer keyring of signer1020 * @param collectionId ID of collection1013 * @param collectionId ID of collection1021 * @param permissions permissions to change a property by the collection owner or admin1014 * @param permissions permissions to change a property by the collection owner or admin1022 * @param label 1023 * @example setTokenPropertyPermissions(1015 * @example setTokenPropertyPermissions(1024 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]1016 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]1025 * )1017 * )1026 * @returns true if extrinsic success otherwise false1018 * @returns true if extrinsic success otherwise false1027 */1019 */1028 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[], label?: string): Promise<boolean> {1020 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[]): Promise<boolean> {1029 if(typeof label === 'undefined') label = `collection #${collectionId}`;1030 const result = await this.helper.executeExtrinsic(1021 const result = await this.helper.executeExtrinsic(1031 signer,1022 signer,1032 'api.tx.unique.setTokenPropertyPermissions', [collectionId, permissions],1023 'api.tx.unique.setTokenPropertyPermissions', [collectionId, permissions],1033 true, `Unable to set token property permissions for ${label}`,1024 true,1034 );1025 );103510261036 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet', label);1027 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet');1037 }1028 }103810291039 /**1030 /**1040 * Set token properties1031 * Set token properties1032 * 1041 * @param signer keyring of signer1033 * @param signer keyring of signer1042 * @param collectionId ID of collection1034 * @param collectionId ID of collection1043 * @param tokenId ID of token1035 * @param tokenId ID of token1044 * @param properties 1036 * @param properties key-value pairs of metadata which to add to a token. Keys must be permitted in the collection1045 * @param label 1046 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1037 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1047 * @returns ```true``` if extrinsic success, otherwise ```false```1038 * @returns ```true``` if extrinsic success, otherwise ```false```1048 */1039 */1049 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[], label?: string): Promise<boolean> {1040 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[]): Promise<boolean> {1050 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;1051 const result = await this.helper.executeExtrinsic(1041 const result = await this.helper.executeExtrinsic(1052 signer,1042 signer,1053 'api.tx.unique.setTokenProperties', [collectionId, tokenId, properties],1043 'api.tx.unique.setTokenProperties', [collectionId, tokenId, properties],1054 true, `Unable to set token properties for ${label}`,1044 true,1055 );1045 );105610461057 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet', label);1047 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet');1058 }1048 }105910491060 /**1050 /**1063 * @param collectionId ID of collection1053 * @param collectionId ID of collection1064 * @param tokenId ID of token1054 * @param tokenId ID of token1065 * @param propertyKeys property keys to be deleted 1055 * @param propertyKeys property keys to be deleted 1066 * @param label 1067 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])1056 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])1068 * @returns ```true``` if extrinsic success, otherwise ```false```1057 * @returns ```true``` if extrinsic success, otherwise ```false```1069 */1058 */1070 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[], label?: string): Promise<boolean> {1059 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[]): Promise<boolean> {1071 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;1072 const result = await this.helper.executeExtrinsic(1060 const result = await this.helper.executeExtrinsic(1073 signer,1061 signer,1074 'api.tx.unique.deleteTokenProperties', [collectionId, tokenId, propertyKeys],1062 'api.tx.unique.deleteTokenProperties', [collectionId, tokenId, propertyKeys],1075 true, `Unable to delete token properties for ${label}`,1063 true,1076 );1064 );107710651078 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted', label);1066 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted');1079 }1067 }108010681081 /**1069 /**1082 * Mint new collection1070 * Mint new collection1071 * 1083 * @param signer keyring of signer1072 * @param signer keyring of signer1084 * @param collectionOptions basic collection options and properties 1073 * @param collectionOptions basic collection options and properties 1085 * @param mode NFT or RFT type of a collection1074 * @param mode NFT or RFT type of a collection1086 * @param errorLabel 1087 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")1075 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")1088 * @returns object of the created collection1076 * @returns object of the created collection1089 */1077 */1090 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT', errorLabel = 'Unable to mint collection'): Promise<UniqueCollectionBase> {1078 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT'): Promise<UniqueCollectionBase> {1091 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1079 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1092 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};1080 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};1093 for (const key of ['name', 'description', 'tokenPrefix']) {1081 for (const key of ['name', 'description', 'tokenPrefix']) {1096 const creationResult = await this.helper.executeExtrinsic(1084 const creationResult = await this.helper.executeExtrinsic(1097 signer,1085 signer,1098 'api.tx.unique.createCollectionEx', [collectionOptions],1086 'api.tx.unique.createCollectionEx', [collectionOptions],1099 true, errorLabel,1087 true, // errorLabel,1100 );1088 );1101 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));1089 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));1102 }1090 }110310911104 getCollectionObject(_collectionId: number): any {1092 getCollectionObject(_collectionId: number): any {1137 * Get token's owner1125 * Get token's owner1138 * @param collectionId ID of collection1126 * @param collectionId ID of collection1139 * @param tokenId ID of token1127 * @param tokenId ID of token1140 * @param blockHashAt 1128 * @param blockHashAt optionally query the data at the block with this hash1141 * @example getTokenOwner(10, 5);1129 * @example getTokenOwner(10, 5);1142 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1130 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1143 */1131 */1219 * Get tokens nested in the provided token1207 * Get tokens nested in the provided token1220 * @param collectionId ID of collection1208 * @param collectionId ID of collection1221 * @param tokenId ID of token1209 * @param tokenId ID of token1222 * @param blockHashAt 1210 * @param blockHashAt optionally query the data at the block with this hash1223 * @example getTokenChildren(10, 5);1211 * @example getTokenChildren(10, 5);1224 * @returns tokens whose depth of nesting is <= 5 1212 * @returns tokens whose depth of nesting is <= 5 1225 */1213 */1241 * @param signer keyring of signer1229 * @param signer keyring of signer1242 * @param tokenObj token to be nested1230 * @param tokenObj token to be nested1243 * @param rootTokenObj token to be parent1231 * @param rootTokenObj token to be parent1244 * @param label 1245 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});1232 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});1246 * @returns ```true``` if extrinsic success, otherwise ```false```1233 * @returns ```true``` if extrinsic success, otherwise ```false```1247 */1234 */1248 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, label='nest token'): Promise<boolean> {1235 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken): Promise<boolean> {1249 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1236 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1250 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1237 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1251 if(!result) {1238 if(!result) {1252 throw Error(`Unable to nest token for ${label}`);1239 throw Error('Unable to nest token!');1253 }1240 }1254 return result;1241 return result;1255 }1242 }1260 * @param tokenObj token to unnest1247 * @param tokenObj token to unnest1261 * @param rootTokenObj parent of a token1248 * @param rootTokenObj parent of a token1262 * @param toAddressObj address of a new token owner 1249 * @param toAddressObj address of a new token owner 1263 * @param label 1264 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});1250 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});1265 * @returns ```true``` if extrinsic success, otherwise ```false```1251 * @returns ```true``` if extrinsic success, otherwise ```false```1266 */1252 */1267 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId, label='unnest token'): Promise<boolean> {1253 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId): Promise<boolean> {1268 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1254 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1269 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1255 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1270 if(!result) {1256 if(!result) {1271 throw Error(`Unable to unnest token for ${label}`);1257 throw Error('Unable to unnest token!');1272 }1258 }1273 return result;1259 return result;1274 }1260 }1277 * Mint new collection1263 * Mint new collection1278 * @param signer keyring of signer1264 * @param signer keyring of signer1279 * @param collectionOptions Collection options1265 * @param collectionOptions Collection options1280 * @param label 1281 * @example 1266 * @example 1282 * mintCollection(aliceKeyring, {1267 * mintCollection(aliceKeyring, {1283 * name: 'New',1268 * name: 'New',1286 * })1271 * })1287 * @returns object of the created collection1272 * @returns object of the created collection1288 */1273 */1289 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueNFTCollection> {1274 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions): Promise<UniqueNFTCollection> {1290 return await super.mintCollection(signer, collectionOptions, 'NFT', `Unable to mint NFT collection for ${label}`) as UniqueNFTCollection;1275 return await super.mintCollection(signer, collectionOptions, 'NFT') as UniqueNFTCollection;1291 }1276 }129212771293 /**1278 /**1294 * Mint new token1279 * Mint new token1295 * @param signer keyring of signer1280 * @param signer keyring of signer1296 * @param data token data1281 * @param data token data1297 * @param label 1298 * @returns created token object1282 * @returns created token object1299 */1283 */1300 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }, label?: string): Promise<UniqueNFTToken> {1284 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }): Promise<UniqueNFTToken> {1301 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;1302 const creationResult = await this.helper.executeExtrinsic(1285 const creationResult = await this.helper.executeExtrinsic(1303 signer,1286 signer,1304 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1287 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1305 nft: {1288 nft: {1306 properties: data.properties,1289 properties: data.properties,1307 },1290 },1308 }],1291 }],1309 true, `Unable to mint NFT token for ${label}`,1292 true,1310 );1293 );1311 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult, label);1294 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult);1312 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1295 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1313 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1296 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1314 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1297 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1319 * @param signer keyring of signer1302 * @param signer keyring of signer1320 * @param collectionId ID of collection1303 * @param collectionId ID of collection1321 * @param tokens array of tokens with owner and properties1304 * @param tokens array of tokens with owner and properties1322 * @param label 1323 * @example 1305 * @example 1324 * mintMultipleTokens(aliceKeyring, 10, [{1306 * mintMultipleTokens(aliceKeyring, 10, [{1325 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},1307 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},1330 * }]);1312 * }]);1331 * @returns ```true``` if extrinsic success, otherwise ```false```1313 * @returns ```true``` if extrinsic success, otherwise ```false```1332 */1314 */1333 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1315 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[]): Promise<UniqueNFTToken[]> {1334 if(typeof label === 'undefined') label = `collection #${collectionId}`;1335 const creationResult = await this.helper.executeExtrinsic(1316 const creationResult = await this.helper.executeExtrinsic(1336 signer,1317 signer,1337 'api.tx.unique.createMultipleItemsEx', [collectionId, {NFT: tokens}],1318 'api.tx.unique.createMultipleItemsEx', [collectionId, {NFT: tokens}],1338 true, `Unable to mint NFT tokens for ${label}`,1319 true,1339 );1320 );1340 const collection = this.getCollectionObject(collectionId);1321 const collection = this.getCollectionObject(collectionId);1341 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1322 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1342 }1323 }134313241344 /**1325 /**1347 * @param collectionId ID of collection1328 * @param collectionId ID of collection1348 * @param owner tokens owner1329 * @param owner tokens owner1349 * @param tokens array of tokens with owner and properties1330 * @param tokens array of tokens with owner and properties1350 * @param label 1351 * @example1331 * @example1352 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{1332 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{1353 * properties: [{1333 * properties: [{1360 * }]);1340 * }]);1361 * @returns array of newly created tokens1341 * @returns array of newly created tokens1362 */1342 */1363 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1343 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[]): Promise<UniqueNFTToken[]> {1364 if(typeof label === 'undefined') label = `collection #${collectionId}`;1365 const rawTokens = [];1344 const rawTokens = [];1366 for (const token of tokens) {1345 for (const token of tokens) {1367 const raw = {NFT: {properties: token.properties}};1346 const raw = {NFT: {properties: token.properties}};1370 const creationResult = await this.helper.executeExtrinsic(1349 const creationResult = await this.helper.executeExtrinsic(1371 signer,1350 signer,1372 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1351 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1373 true, `Unable to mint NFT tokens for ${label}`,1352 true,1374 );1353 );1375 const collection = this.getCollectionObject(collectionId);1354 const collection = this.getCollectionObject(collectionId);1376 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1355 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1377 }1356 }137813571379 /**1358 /**1380 * Destroys a concrete instance of NFT.1359 * Destroys a concrete instance of NFT.1381 * @param signer keyring of signer1360 * @param signer keyring of signer1382 * @param collectionId ID of collection1361 * @param collectionId ID of collection1383 * @param tokenId ID of token1362 * @param tokenId ID of token1384 * @param label 1385 * @example burnToken(aliceKeyring, 10, 5);1363 * @example burnToken(aliceKeyring, 10, 5);1386 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1364 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1387 */1365 */1388 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string): Promise<{ success: boolean; token: number | null; }> {1366 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number): Promise<{ success: boolean; token: number | null; }> {1389 return await super.burnToken(signer, collectionId, tokenId, label, 1n);1367 return await super.burnToken(signer, collectionId, tokenId, 1n);1390 }1368 }139113691392 /**1370 /**1396 * @param collectionId ID of collection1374 * @param collectionId ID of collection1397 * @param tokenId ID of token1375 * @param tokenId ID of token1398 * @param toAddressObj address to approve1376 * @param toAddressObj address to approve1399 * @param label 1400 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1377 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1401 * @returns ```true``` if extrinsic success, otherwise ```false```1378 * @returns ```true``` if extrinsic success, otherwise ```false```1402 */1379 */1403 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {1380 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId) {1404 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, 1n);1381 return super.approveToken(signer, collectionId, tokenId, toAddressObj, 1n);1405 }1382 }1406}1383}140713841461 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, 2000n)1438 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, 2000n)1462 * @returns ```true``` if extrinsic success, otherwise ```false```1439 * @returns ```true``` if extrinsic success, otherwise ```false```1463 */1440 */1464 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=100n): Promise<boolean> {1441 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=1n): Promise<boolean> {1465 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);1442 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);1466 }1443 }146714441476 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)1453 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)1477 * @returns ```true``` if extrinsic success, otherwise ```false```1454 * @returns ```true``` if extrinsic success, otherwise ```false```1478 */1455 */1479 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n): Promise<boolean> {1456 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {1480 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);1457 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);1481 }1458 }148214591483 /**1460 /**1484 * Mint new collection1461 * Mint new collection1485 * @param signer keyring of signer1462 * @param signer keyring of signer1486 * @param collectionOptions Collection options1463 * @param collectionOptions Collection options1487 * @param label 1488 * @example1464 * @example1489 * mintCollection(aliceKeyring, {1465 * mintCollection(aliceKeyring, {1490 * name: 'New',1466 * name: 'New',1493 * })1469 * })1494 * @returns object of the created collection1470 * @returns object of the created collection1495 */1471 */1496 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueRFTCollection> {1472 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions): Promise<UniqueRFTCollection> {1497 return await super.mintCollection(signer, collectionOptions, 'RFT', `Unable to mint RFT collection for ${label}`) as UniqueRFTCollection;1473 return await super.mintCollection(signer, collectionOptions, 'RFT') as UniqueRFTCollection;1498 }1474 }149914751500 /**1476 /**1501 * Mint new token1477 * Mint new token1502 * @param signer keyring of signer1478 * @param signer keyring of signer1503 * @param data token data1479 * @param data token data1504 * @param label 1505 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});1480 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});1506 * @returns created token object1481 * @returns created token object1507 */1482 */1508 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }, label?: string): Promise<UniqueRFTToken> {1483 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }): Promise<UniqueRFTToken> {1509 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;1510 const creationResult = await this.helper.executeExtrinsic(1484 const creationResult = await this.helper.executeExtrinsic(1511 signer,1485 signer,1512 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1486 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1515 properties: data.properties,1489 properties: data.properties,1516 },1490 },1517 }],1491 }],1518 true, `Unable to mint RFT token for ${label}`,1492 true,1519 );1493 );1520 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult, label);1494 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult);1521 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1495 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1522 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1496 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1523 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1497 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1524 }1498 }152514991526 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {1500 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[]): Promise<UniqueRFTToken[]> {1527 throw Error('Not implemented');1501 throw Error('Not implemented');1528 if(typeof label === 'undefined') label = `collection #${collectionId}`;1529 const creationResult = await this.helper.executeExtrinsic(1502 const creationResult = await this.helper.executeExtrinsic(1530 signer,1503 signer,1531 'api.tx.unique.createMultipleItemsEx', [collectionId, {RefungibleMultipleOwners: tokens}],1504 'api.tx.unique.createMultipleItemsEx', [collectionId, {RefungibleMultipleOwners: tokens}],1532 true, `Unable to mint RFT tokens for ${label}`,1505 true, // `Unable to mint RFT tokens for ${label}`,1533 );1506 );1534 const collection = this.getCollectionObject(collectionId);1507 const collection = this.getCollectionObject(collectionId);1535 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1508 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1536 }1509 }153715101538 /**1511 /**1541 * @param collectionId ID of collection1514 * @param collectionId ID of collection1542 * @param owner tokens owner1515 * @param owner tokens owner1543 * @param tokens array of tokens with properties and pieces1516 * @param tokens array of tokens with properties and pieces1544 * @param label 1545 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);1517 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);1546 * @returns array of newly created RFT tokens1518 * @returns array of newly created RFT tokens1547 */1519 */1548 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {1520 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[]): Promise<UniqueRFTToken[]> {1549 if(typeof label === 'undefined') label = `collection #${collectionId}`;1550 const rawTokens = [];1521 const rawTokens = [];1551 for (const token of tokens) {1522 for (const token of tokens) {1552 const raw = {ReFungible: {pieces: token.pieces, properties: token.properties}};1523 const raw = {ReFungible: {pieces: token.pieces, properties: token.properties}};1555 const creationResult = await this.helper.executeExtrinsic(1526 const creationResult = await this.helper.executeExtrinsic(1556 signer,1527 signer,1557 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1528 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1558 true, `Unable to mint RFT tokens for ${label}`,1529 true,1559 );1530 );1560 const collection = this.getCollectionObject(collectionId);1531 const collection = this.getCollectionObject(collectionId);1561 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1532 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1562 }1533 }156315341564 /**1535 /**1565 * Destroys a concrete instance of RFT.1536 * Destroys a concrete instance of RFT.1566 * @param signer keyring of signer1537 * @param signer keyring of signer1567 * @param collectionId ID of collection1538 * @param collectionId ID of collection1568 * @param tokenId ID of token1539 * @param tokenId ID of token1569 * @param label 1570 * @param amount number of pieces to be burnt1540 * @param amount number of pieces to be burnt1571 * @example burnToken(aliceKeyring, 10, 5);1541 * @example burnToken(aliceKeyring, 10, 5);1572 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1542 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1573 */1543 */1574 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string, amount=100n): Promise<{ success: boolean; token: number | null; }> {1544 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, amount=1n): Promise<{ success: boolean; token: number | null; }> {1575 return await super.burnToken(signer, collectionId, tokenId, label, amount);1545 return await super.burnToken(signer, collectionId, tokenId, amount);1576 }1546 }157715471578 /**1548 /**1582 * @param collectionId ID of collection1552 * @param collectionId ID of collection1583 * @param tokenId ID of token1553 * @param tokenId ID of token1584 * @param toAddressObj address to approve1554 * @param toAddressObj address to approve1585 * @param label 1586 * @param amount number of pieces to be approved1555 * @param amount number of pieces to be approved1587 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);1556 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);1588 * @returns true if the token success, otherwise false1557 * @returns true if the token success, otherwise false1589 */1558 */1590 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=100n) {1559 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {1591 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, amount);1560 return super.approveToken(signer, collectionId, tokenId, toAddressObj, amount);1592 }1561 }159315621594 /**1563 /**1608 * @param collectionId ID of collection1577 * @param collectionId ID of collection1609 * @param tokenId ID of token1578 * @param tokenId ID of token1610 * @param amount new number of pieces1579 * @param amount new number of pieces1611 * @param label 1612 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);1580 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);1613 * @returns true if the repartion was success, otherwise false1581 * @returns true if the repartion was success, otherwise false1614 */1582 */1615 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint, label?: string): Promise<boolean> {1583 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint): Promise<boolean> {1616 if(typeof label === 'undefined') label = `collection #${collectionId}`;1617 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);1584 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);1618 const repartitionResult = await this.helper.executeExtrinsic(1585 const repartitionResult = await this.helper.executeExtrinsic(1619 signer,1586 signer,1620 'api.tx.unique.repartition', [collectionId, tokenId, amount],1587 'api.tx.unique.repartition', [collectionId, tokenId, amount],1621 true, `Unable to repartition RFT token for ${label}`,1588 true,1622 );1589 );1623 if(currentAmount < amount) return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemCreated', label);1590 if(currentAmount < amount) return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemCreated');1624 return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemDestroyed', label);1591 return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemDestroyed');1625 }1592 }1626}1593}162715941642 * @param signer keyring of signer1609 * @param signer keyring of signer1643 * @param collectionOptions Collection options1610 * @param collectionOptions Collection options1644 * @param decimalPoints number of token decimals 1611 * @param decimalPoints number of token decimals 1645 * @param errorLabel 1646 * @example1612 * @example1647 * mintCollection(aliceKeyring, {1613 * mintCollection(aliceKeyring, {1648 * name: 'New',1614 * name: 'New',1651 * }, 18)1617 * }, 18)1652 * @returns newly created fungible collection1618 * @returns newly created fungible collection1653 */1619 */1654 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0, errorLabel = 'Unable to mint collection'): Promise<UniqueFTCollection> {1620 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0): Promise<UniqueFTCollection> {1655 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1621 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1656 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');1622 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');1657 collectionOptions.mode = {fungible: decimalPoints};1623 collectionOptions.mode = {fungible: decimalPoints};1661 const creationResult = await this.helper.executeExtrinsic(1627 const creationResult = await this.helper.executeExtrinsic(1662 signer,1628 signer,1663 'api.tx.unique.createCollectionEx', [collectionOptions],1629 'api.tx.unique.createCollectionEx', [collectionOptions],1664 true, errorLabel,1630 true,1665 );1631 );1666 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));1632 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));1667 }1633 }166816341669 /**1635 /**1672 * @param collectionId ID of collection1638 * @param collectionId ID of collection1673 * @param owner address owner of new tokens1639 * @param owner address owner of new tokens1674 * @param amount amount of tokens to be meanted1640 * @param amount amount of tokens to be meanted1675 * @param label 1676 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1641 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1677 * @returns ```true``` if extrinsic success, otherwise ```false``` 1642 * @returns ```true``` if extrinsic success, otherwise ```false``` 1678 */1643 */1679 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint, label?: string): Promise<boolean> {1644 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint): Promise<boolean> {1680 if(typeof label === 'undefined') label = `collection #${collectionId}`;1681 const creationResult = await this.helper.executeExtrinsic(1645 const creationResult = await this.helper.executeExtrinsic(1682 signer,1646 signer,1683 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {1647 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {1684 fungible: {1648 fungible: {1685 value: amount,1649 value: amount,1686 },1650 },1687 }],1651 }],1688 true, `Unable to mint fungible tokens for ${label}`,1652 true, // `Unable to mint fungible tokens for ${label}`,1689 );1653 );1690 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1654 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated');1691 }1655 }169216561693 /**1657 /**1696 * @param collectionId ID of collection1660 * @param collectionId ID of collection1697 * @param owner tokens owner1661 * @param owner tokens owner1698 * @param tokens array of tokens with properties and pieces1662 * @param tokens array of tokens with properties and pieces1699 * @param label 1700 * @returns ```true``` if extrinsic success, otherwise ```false``` 1663 * @returns ```true``` if extrinsic success, otherwise ```false``` 1701 */1664 */1702 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string): Promise<boolean> {1665 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[]): Promise<boolean> {1703 if(typeof label === 'undefined') label = `collection #${collectionId}`;1704 const rawTokens = [];1666 const rawTokens = [];1705 for (const token of tokens) {1667 for (const token of tokens) {1706 const raw = {Fungible: {Value: token.value}};1668 const raw = {Fungible: {Value: token.value}};1709 const creationResult = await this.helper.executeExtrinsic(1671 const creationResult = await this.helper.executeExtrinsic(1710 signer,1672 signer,1711 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1673 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1712 true, `Unable to mint RFT tokens for ${label}`,1674 true,1713 );1675 );1714 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1676 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated');1715 }1677 }171616781717 /**1679 /**1739 * Transfer tokens to address1701 * Transfer tokens to address1740 * @param signer keyring of signer1702 * @param signer keyring of signer1741 * @param collectionId ID of collection1703 * @param collectionId ID of collection1742 * @param toAddressObj address recepient1704 * @param toAddressObj address recipient1743 * @param amount amount of tokens to be sent1705 * @param amount amount of tokens to be sent1744 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1706 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1745 * @returns ```true``` if extrinsic success, otherwise ```false``` 1707 * @returns ```true``` if extrinsic success, otherwise ```false``` 1746 */1708 */1747 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount: bigint) {1709 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {1748 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1710 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1749 }1711 }175017121758 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);1720 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);1759 * @returns ```true``` if extrinsic success, otherwise ```false``` 1721 * @returns ```true``` if extrinsic success, otherwise ```false``` 1760 */1722 */1761 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {1723 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {1762 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);1724 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);1763 }1725 }176417261767 * @param signer keyring of signer1729 * @param signer keyring of signer1768 * @param collectionId ID of collection1730 * @param collectionId ID of collection1769 * @param amount amount of tokens to be destroyed1731 * @param amount amount of tokens to be destroyed1770 * @param label 1771 * @example burnTokens(aliceKeyring, 10, 1000n);1732 * @example burnTokens(aliceKeyring, 10, 1000n);1772 * @returns ```true``` if extrinsic success, otherwise ```false``` 1733 * @returns ```true``` if extrinsic success, otherwise ```false``` 1773 */1734 */1774 async burnTokens(signer: IKeyringPair, collectionId: number, amount=100n, label?: string): Promise<boolean> {1735 async burnTokens(signer: IKeyringPair, collectionId: number, amount=1n): Promise<boolean> {1775 return (await super.burnToken(signer, collectionId, 0, label, amount)).success;1736 return (await super.burnToken(signer, collectionId, 0, amount)).success;1776 }1737 }177717381778 /**1739 /**1781 * @param collectionId ID of collection1742 * @param collectionId ID of collection1782 * @param fromAddressObj address on behalf of which tokens will be burnt1743 * @param fromAddressObj address on behalf of which tokens will be burnt1783 * @param amount amount of tokens to be burnt1744 * @param amount amount of tokens to be burnt1784 * @param label 1785 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1745 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1786 * @returns ```true``` if extrinsic success, otherwise ```false``` 1746 * @returns ```true``` if extrinsic success, otherwise ```false``` 1787 */1747 */1788 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=100n, label?: string): Promise<boolean> {1748 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {1789 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, label, amount);1749 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, amount);1790 }1750 }179117511792 /**1752 /**1805 * @param collectionId ID of collection1765 * @param collectionId ID of collection1806 * @param toAddressObj address to be approved1766 * @param toAddressObj address to be approved1807 * @param amount amount of tokens to be approved1767 * @param amount amount of tokens to be approved1808 * @param label 1809 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)1768 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)1810 * @returns ```true``` if extrinsic success, otherwise ```false``` 1769 * @returns ```true``` if extrinsic success, otherwise ```false``` 1811 */1770 */1812 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {1771 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {1813 return super.approveToken(signer, collectionId, 0, toAddressObj, label, amount);1772 return super.approveToken(signer, collectionId, 0, toAddressObj, amount);1814 }1773 }181517741816 /**1775 /**1908 /**1867 /**1909 * Transfer tokens to substrate address1868 * Transfer tokens to substrate address1910 * @param signer keyring of signer1869 * @param signer keyring of signer1911 * @param address substrate address of a recepient1870 * @param address substrate address of a recipient1912 * @param amount amount of tokens to be transfered1871 * @param amount amount of tokens to be transfered1913 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);1872 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);1914 * @returns ```true``` if extrinsic success, otherwise ```false```1873 * @returns ```true``` if extrinsic success, otherwise ```false```1915 */1874 */1916 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1875 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1917 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`);1876 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);191818771919 let transfer = {from: null, to: null, amount: 0n} as any;1878 let transfer = {from: null, to: null, amount: 0n} as any;1920 result.result.events.forEach(({event: {data, method, section}}) => {1879 result.result.events.forEach(({event: {data, method, section}}) => {203519942036 async getEffectiveLimits() {1995 async getEffectiveLimits() {2037 return await this.helper.collection.getEffectiveLimits(this.collectionId);1996 return await this.helper.collection.getEffectiveLimits(this.collectionId);1997 }19981999 async setSponsor(signer: TSigner, sponsorAddress: TSubstrateAccount) {2000 return await this.helper.collection.setSponsor(signer, this.collectionId, sponsorAddress);2001 }20022003 async confirmSponsorship(signer: TSigner) {2004 return await this.helper.collection.confirmSponsorship(signer, this.collectionId);2038 }2005 }203920062040 async setSponsor(signer: TSigner, sponsorAddress: TSubstrateAccount, label?: string) {2007 async setLimits(signer: TSigner, limits: ICollectionLimits) {2041 return await this.helper.collection.setSponsor(signer, this.collectionId, sponsorAddress, label);2008 return await this.helper.collection.setLimits(signer, this.collectionId, limits);2042 }2009 }204320102044 async confirmSponsorship(signer: TSigner, label?: string) {2011 async changeOwner(signer: TSigner, ownerAddress: TSubstrateAccount) {2045 return await this.helper.collection.confirmSponsorship(signer, this.collectionId, label);2012 return await this.helper.collection.changeOwner(signer, this.collectionId, ownerAddress);2046 }2013 }204720142048 async setLimits(signer: TSigner, limits: ICollectionLimits, label?: string) {2015 async addAdmin(signer: TSigner, adminAddressObj: ICrossAccountId) {2049 return await this.helper.collection.setLimits(signer, this.collectionId, limits, label);2016 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj);2050 }2017 }205120182052 async changeOwner(signer: TSigner, ownerAddress: TSubstrateAccount, label?: string) {2019 async enableAllowList(signer: TSigner, value = true/*: 'Normal' | 'AllowList' = 'AllowList'*/) {2053 return await this.helper.collection.changeOwner(signer, this.collectionId, ownerAddress, label);2020 return await this.setPermissions(signer, value ? {access: 'AllowList', mintMode: true} : {access: 'Normal'});2054 }2021 }205520222056 async addAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {2023 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId) {2057 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj, label);2024 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj);2058 }2025 }205920262060 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId, label?: string) {2027 async removeFromAllowList(signer: TSigner, addressObj: ICrossAccountId) {2061 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj, label);2028 return await this.helper.collection.removeFromAllowList(signer, this.collectionId, addressObj);2062 }2029 }206320302064 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {2031 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId) {2065 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj, label);2032 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj);2066 }2033 }206720342068 async setProperties(signer: TSigner, properties: IProperty[], label?: string) {2035 async setProperties(signer: TSigner, properties: IProperty[]) {2069 return await this.helper.collection.setProperties(signer, this.collectionId, properties, label);2036 return await this.helper.collection.setProperties(signer, this.collectionId, properties);2070 }2037 }207120382072 async deleteProperties(signer: TSigner, propertyKeys: string[], label?: string) {2039 async deleteProperties(signer: TSigner, propertyKeys: string[]) {2073 return await this.helper.collection.deleteProperties(signer, this.collectionId, propertyKeys, label);2040 return await this.helper.collection.deleteProperties(signer, this.collectionId, propertyKeys);2074 }2041 }207520422076 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {2043 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {2077 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);2044 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);2078 }2045 }207920462080 async setPermissions(signer: TSigner, permissions: ICollectionPermissions, label?: string) {2047 async setPermissions(signer: TSigner, permissions: ICollectionPermissions) {2081 return await this.helper.collection.setPermissions(signer, this.collectionId, permissions, label);2048 return await this.helper.collection.setPermissions(signer, this.collectionId, permissions);2082 }2049 }208320502084 async enableNesting(signer: TSigner, permissions: INestingPermissions, label?: string) {2051 async enableNesting(signer: TSigner, permissions: INestingPermissions) {2085 return await this.helper.collection.enableNesting(signer, this.collectionId, permissions, label);2052 return await this.helper.collection.enableNesting(signer, this.collectionId, permissions);2086 }2053 }208720542088 async disableNesting(signer: TSigner, label?: string) {2055 async disableNesting(signer: TSigner) {2089 return await this.helper.collection.disableNesting(signer, this.collectionId, label);2056 return await this.helper.collection.disableNesting(signer, this.collectionId);2090 }2057 }209120582092 async burn(signer: TSigner, label?: string) {2059 async burn(signer: TSigner) {2093 return await this.helper.collection.burn(signer, this.collectionId, label);2060 return await this.helper.collection.burn(signer, this.collectionId);2094 }2061 }2095}2062}209620632105 }2072 }210620732107 async getToken(tokenId: number, blockHashAt?: string) {2074 async getToken(tokenId: number, blockHashAt?: string) {2108 return await this.helper.nft.getToken(this.collectionId, tokenId, blockHashAt);2075 return await this.helper.nft.getToken(this.collectionId, tokenId, [], blockHashAt);2109 }2076 }211020772111 async getTokenOwner(tokenId: number, blockHashAt?: string) {2078 async getTokenOwner(tokenId: number, blockHashAt?: string) {2128 return await this.helper.nft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj);2095 return await this.helper.nft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj);2129 }2096 }213020972131 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {2098 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId) {2132 return await this.helper.nft.approveToken(signer, this.collectionId, tokenId, toAddressObj, label);2099 return await this.helper.nft.approveToken(signer, this.collectionId, tokenId, toAddressObj);2133 }2100 }213421012135 async isTokenApproved(tokenId: number, toAddressObj: ICrossAccountId) {2102 async isTokenApproved(tokenId: number, toAddressObj: ICrossAccountId) {2136 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);2103 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);2137 }2104 }213821052139 async mintToken(signer: TSigner, owner: ICrossAccountId, properties?: IProperty[], label?: string) {2106 async mintToken(signer: TSigner, owner: ICrossAccountId, properties?: IProperty[]) {2140 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties}, label);2107 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties});2141 }2108 }214221092143 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string) {2110 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[]) {2144 return await this.helper.nft.mintMultipleTokens(signer, this.collectionId, tokens, label);2111 return await this.helper.nft.mintMultipleTokens(signer, this.collectionId, tokens);2145 }2112 }214621132147 async burnToken(signer: TSigner, tokenId: number, label?: string) {2114 async burnToken(signer: TSigner, tokenId: number) {2148 return await this.helper.nft.burnToken(signer, this.collectionId, tokenId, label);2115 return await this.helper.nft.burnToken(signer, this.collectionId, tokenId);2149 }2116 }215021172151 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[], label?: string) {2118 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[]) {2152 return await this.helper.nft.setTokenProperties(signer, this.collectionId, tokenId, properties, label);2119 return await this.helper.nft.setTokenProperties(signer, this.collectionId, tokenId, properties);2153 }2120 }215421212155 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[], label?: string) {2122 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[]) {2156 return await this.helper.nft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys, label);2123 return await this.helper.nft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys);2157 }2124 }215821252159 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[], label?: string) {2126 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[]) {2160 return await this.helper.nft.setTokenPropertyPermissions(signer, this.collectionId, permissions, label);2127 return await this.helper.nft.setTokenPropertyPermissions(signer, this.collectionId, permissions);2161 }2128 }216221292163 async nestToken(signer: TSigner, tokenId: number, toTokenObj: IToken, label?: string) {2130 async nestToken(signer: TSigner, tokenId: number, toTokenObj: IToken) {2164 return await this.helper.nft.nestToken(signer, {collectionId: this.collectionId, tokenId}, toTokenObj, label);2131 return await this.helper.nft.nestToken(signer, {collectionId: this.collectionId, tokenId}, toTokenObj);2165 }2132 }216621332167 async unnestToken(signer: TSigner, tokenId: number, fromTokenObj: IToken, toAddressObj: ICrossAccountId, label?: string) {2134 async unnestToken(signer: TSigner, tokenId: number, fromTokenObj: IToken, toAddressObj: ICrossAccountId) {2168 return await this.helper.nft.unnestToken(signer, {collectionId: this.collectionId, tokenId}, fromTokenObj, toAddressObj, label);2135 return await this.helper.nft.unnestToken(signer, {collectionId: this.collectionId, tokenId}, fromTokenObj, toAddressObj);2169 }2136 }2170}2137}217121382191 return await this.helper.rft.getTokenTotalPieces(this.collectionId, tokenId);2158 return await this.helper.rft.getTokenTotalPieces(this.collectionId, tokenId);2192 }2159 }219321602194 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=100n) {2161 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=1n) {2195 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);2162 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);2196 }2163 }219721642198 async transferTokenFrom(signer: TSigner, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n) {2165 async transferTokenFrom(signer: TSigner, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {2199 return await this.helper.rft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj, amount);2166 return await this.helper.rft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj, amount);2200 }2167 }220121682202 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2169 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {2203 return await this.helper.rft.approveToken(signer, this.collectionId, tokenId, toAddressObj, label, amount);2170 return await this.helper.rft.approveToken(signer, this.collectionId, tokenId, toAddressObj, amount);2204 }2171 }220521722206 async getTokenApprovedPieces(tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2173 async getTokenApprovedPieces(tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2207 return await this.helper.rft.getTokenApprovedPieces(this.collectionId, tokenId, toAddressObj, fromAddressObj);2174 return await this.helper.rft.getTokenApprovedPieces(this.collectionId, tokenId, toAddressObj, fromAddressObj);2208 }2175 }220921762210 async repartitionToken(signer: TSigner, tokenId: number, amount: bigint, label?: string) {2177 async repartitionToken(signer: TSigner, tokenId: number, amount: bigint) {2211 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount, label);2178 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount);2212 }2179 }221321802214 async mintToken(signer: TSigner, owner: ICrossAccountId, pieces=100n, properties?: IProperty[], label?: string) {2181 async mintToken(signer: TSigner, owner: ICrossAccountId, pieces=100n, properties?: IProperty[]) {2215 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties}, label);2182 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties});2216 }2183 }221721842218 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[], label?: string) {2185 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[]) {2219 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens, label);2186 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens);2220 }2187 }222121882222 async burnToken(signer: TSigner, tokenId: number, amount=100n, label?: string) {2189 async burnToken(signer: TSigner, tokenId: number, amount=1n) {2223 return await this.helper.rft.burnToken(signer, this.collectionId, tokenId, label, amount);2190 return await this.helper.rft.burnToken(signer, this.collectionId, tokenId, amount);2224 }2191 }222521922226 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[], label?: string) {2193 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[]) {2227 return await this.helper.rft.setTokenProperties(signer, this.collectionId, tokenId, properties, label);2194 return await this.helper.rft.setTokenProperties(signer, this.collectionId, tokenId, properties);2228 }2195 }222921962230 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[], label?: string) {2197 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[]) {2231 return await this.helper.rft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys, label);2198 return await this.helper.rft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys);2232 }2199 }223322002234 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[], label?: string) {2201 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[]) {2235 return await this.helper.rft.setTokenPropertyPermissions(signer, this.collectionId, permissions, label);2202 return await this.helper.rft.setTokenPropertyPermissions(signer, this.collectionId, permissions);2236 }2203 }2237}2204}22382205223922062240class UniqueFTCollection extends UniqueCollectionBase {2207class UniqueFTCollection extends UniqueCollectionBase {2241 async mint(signer: TSigner, owner: ICrossAccountId, amount: bigint, label?: string) {2208 async mint(signer: TSigner, owner: ICrossAccountId, amount: bigint) {2242 return await this.helper.ft.mintTokens(signer, this.collectionId, owner, amount, label);2209 return await this.helper.ft.mintTokens(signer, this.collectionId, owner, amount);2243 }2210 }224422112245 async mintWithOneOwner(signer: TSigner, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string) {2212 async mintWithOneOwner(signer: TSigner, owner: ICrossAccountId, tokens: {value: bigint}[]) {2246 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, owner, tokens, label);2213 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, owner, tokens);2247 }2214 }224822152249 async getBalance(addressObj: ICrossAccountId) {2216 async getBalance(addressObj: ICrossAccountId) {2254 return await this.helper.ft.getTop10Owners(this.collectionId);2221 return await this.helper.ft.getTop10Owners(this.collectionId);2255 }2222 }225622232257 async transfer(signer: TSigner, toAddressObj: ICrossAccountId, amount: bigint) {2224 async transfer(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {2258 return await this.helper.ft.transfer(signer, this.collectionId, toAddressObj, amount);2225 return await this.helper.ft.transfer(signer, this.collectionId, toAddressObj, amount);2259 }2226 }226022272261 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {2228 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {2262 return await this.helper.ft.transferFrom(signer, this.collectionId, fromAddressObj, toAddressObj, amount);2229 return await this.helper.ft.transferFrom(signer, this.collectionId, fromAddressObj, toAddressObj, amount);2263 }2230 }226422312265 async burnTokens(signer: TSigner, amount: bigint, label?: string) {2232 async burnTokens(signer: TSigner, amount=1n) {2266 return await this.helper.ft.burnTokens(signer, this.collectionId, amount, label);2233 return await this.helper.ft.burnTokens(signer, this.collectionId, amount);2267 }2234 }226822352269 async burnTokensFrom(signer: TSigner, fromAddressObj: ICrossAccountId, amount: bigint, label?: string) {2236 async burnTokensFrom(signer: TSigner, fromAddressObj: ICrossAccountId, amount=1n) {2270 return await this.helper.ft.burnTokensFrom(signer, this.collectionId, fromAddressObj, amount, label);2237 return await this.helper.ft.burnTokensFrom(signer, this.collectionId, fromAddressObj, amount);2271 }2238 }227222392273 async getTotalPieces() {2240 async getTotalPieces() {2274 return await this.helper.ft.getTotalPieces(this.collectionId);2241 return await this.helper.ft.getTotalPieces(this.collectionId);2275 }2242 }227622432277 async approveTokens(signer: TSigner, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2244 async approveTokens(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {2278 return await this.helper.ft.approveTokens(signer, this.collectionId, toAddressObj, amount, label);2245 return await this.helper.ft.approveTokens(signer, this.collectionId, toAddressObj, amount);2279 }2246 }228022472281 async getApprovedTokens(fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2248 async getApprovedTokens(fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2299 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);2266 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);2300 }2267 }230122682302 async setProperties(signer: TSigner, properties: IProperty[], label?: string) {2269 async setProperties(signer: TSigner, properties: IProperty[]) {2303 return await this.collection.setTokenProperties(signer, this.tokenId, properties, label);2270 return await this.collection.setTokenProperties(signer, this.tokenId, properties);2304 }2271 }230522722306 async deleteProperties(signer: TSigner, propertyKeys: string[], label?: string) {2273 async deleteProperties(signer: TSigner, propertyKeys: string[]) {2307 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys, label);2274 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys);2308 }2275 }2309}2276}231022772333 return await this.collection.getTokenChildren(this.tokenId, blockHashAt);2300 return await this.collection.getTokenChildren(this.tokenId, blockHashAt);2334 }2301 }233523022336 async nest(signer: TSigner, toTokenObj: IToken, label?: string) {2303 async nest(signer: TSigner, toTokenObj: IToken) {2337 return await this.collection.nestToken(signer, this.tokenId, toTokenObj, label);2304 return await this.collection.nestToken(signer, this.tokenId, toTokenObj);2338 }2305 }233923062340 async unnest(signer: TSigner, fromTokenObj: IToken, toAddressObj: ICrossAccountId, label?: string) {2307 async unnest(signer: TSigner, fromTokenObj: IToken, toAddressObj: ICrossAccountId) {2341 return await this.collection.unnestToken(signer, this.tokenId, fromTokenObj, toAddressObj, label);2308 return await this.collection.unnestToken(signer, this.tokenId, fromTokenObj, toAddressObj);2342 }2309 }234323102344 async transfer(signer: TSigner, addressObj: ICrossAccountId) {2311 async transfer(signer: TSigner, addressObj: ICrossAccountId) {2349 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj);2316 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj);2350 }2317 }235123182352 async approve(signer: TSigner, toAddressObj: ICrossAccountId, label?: string) {2319 async approve(signer: TSigner, toAddressObj: ICrossAccountId) {2353 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, label);2320 return await this.collection.approveToken(signer, this.tokenId, toAddressObj);2354 }2321 }235523222356 async isApproved(toAddressObj: ICrossAccountId) {2323 async isApproved(toAddressObj: ICrossAccountId) {2357 return await this.collection.isTokenApproved(this.tokenId, toAddressObj);2324 return await this.collection.isTokenApproved(this.tokenId, toAddressObj);2358 }2325 }235923262360 async burn(signer: TSigner, label?: string) {2327 async burn(signer: TSigner) {2361 return await this.collection.burnToken(signer, this.tokenId, label);2328 return await this.collection.burnToken(signer, this.tokenId);2362 }2329 }2363}2330}236423312382 return await this.collection.getTokenTotalPieces(this.tokenId);2349 return await this.collection.getTokenTotalPieces(this.tokenId);2383 }2350 }238423512385 async transfer(signer: TSigner, addressObj: ICrossAccountId, amount=100n) {2352 async transfer(signer: TSigner, addressObj: ICrossAccountId, amount=1n) {2386 return await this.collection.transferToken(signer, this.tokenId, addressObj, amount);2353 return await this.collection.transferToken(signer, this.tokenId, addressObj, amount);2387 }2354 }238823552389 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n) {2356 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {2390 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj, amount);2357 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj, amount);2391 }2358 }239223592393 async approve(signer: TSigner, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2360 async approve(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {2394 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, amount, label);2361 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, amount);2395 }2362 }239623632397 async getApprovedPieces(fromAddressObj: ICrossAccountId, toAccountObj: ICrossAccountId) {2364 async getApprovedPieces(fromAddressObj: ICrossAccountId, toAccountObj: ICrossAccountId) {2398 return await this.collection.getTokenApprovedPieces(this.tokenId, fromAddressObj, toAccountObj);2365 return await this.collection.getTokenApprovedPieces(this.tokenId, fromAddressObj, toAccountObj);2399 }2366 }240023672401 async repartition(signer: TSigner, amount: bigint, label?: string) {2368 async repartition(signer: TSigner, amount: bigint) {2402 return await this.collection.repartitionToken(signer, this.tokenId, amount, label);2369 return await this.collection.repartitionToken(signer, this.tokenId, amount);2403 }2370 }240423712405 async burn(signer: TSigner, amount=100n, label?: string) {2372 async burn(signer: TSigner, amount=1n) {2406 return await this.collection.burnToken(signer, this.tokenId, amount, label);2373 return await this.collection.burnToken(signer, this.tokenId, amount);2407 }2374 }2408}2375}