From 695021eeed196de27cdabf79469fe6a80f577e0f Mon Sep 17 00:00:00 2001 From: Nate Geier Date: Tue, 20 Apr 2021 09:29:19 +0100 Subject: [PATCH] Still need 1 yacto to be added, thor is on it --- src/wallet.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/wallet.ts b/src/wallet.ts index dc499dee3..b0246017f 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -264,6 +264,32 @@ export class Wallet { await contract.batch_transfer({ token_ids: tokenIds }, MAX_GAS, YOCTO) } + /** + * Burn one or more tokens. + * @param contractName The contract name to burn tokens from. + * @param tokenIds The mapping of burns, defined by: [[accountName1, tokenId1], [accountName2, tokenId2]] + */ + + // TODO: need more checks on the tokenIds + public async burn(tokenIds: number[], contractName: string): Promise { + const account = this.activeWallet?.account() + const accountId = this.activeWallet?.account().accountId + const MAX_GAS = new BN('300000000000000') + const YOCTO = new BN('1') + + if (!account || !accountId) throw new Error('Account is undefined.') + + if (!contractName) throw new Error('No contract was provided.') + + const contract = new Contract(account, contractName, { + viewMethods: STORE_CONTRACT_VIEW_METHODS, + changeMethods: STORE_CONTRACT_CALL_METHODS, + }) + + // @ts-ignore: method does not exist on Contract type + await contract.batch_burn({ token_ids: tokenIds }, MAX_GAS, YOCTO) + } + /** * List an item for sale in the market. * @param tokenId The token id list.