Casper Mint / Evolve / Burn NFT

You can burn your NFTs if you configure smart contract with this functionality.

// Casper Example

async mint(smartContract: SmartContract, [nft]: NFTView[]) {
        const CasperWalletProvider = (window as any).CasperWalletProvider;
        const provider = CasperWalletProvider();
        const isConnected = await provider.isConnected();
        if (!isConnected) {
            throw new Error('You need to connect with Casper Wallet');
        }
     
        const publicKeyHex = await provider.getActivePublicKey();
        const publicKey = CLPublicKey.fromHex(publicKeyHex);

        const contractClient = new Contracts.Contract(this.casperClient);
        contractClient.setContractHash(smartContract.smartContractAddress!);

        const runtimeArgs = RuntimeArgs.fromMap({
            token_owner: CLValueBuilder.key(publicKey),
            token_meta_data: CLValueBuilder.string(JSON.stringify({
                name: 'minteandome',
                image: nft.path
            })),
        });
        const mintDeploy = contractClient.callEntrypoint('mint || evolve || burn', runtimeArgs, publicKey, 'casper-test', '3000000000');

        const {signature} = await provider.sign(JSON.stringify(DeployUtil.deployToJson(mintDeploy)), publicKeyHex);

        DeployUtil.setSignature(mintDeploy, signature, publicKey);

        const deployHash = await this.casperClient.putDeploy(mintDeploy);
        await this.getDeploy(deployHash);
    }


private async getDeploy(deployHash: string) {
        let i = 300;
        while (i !== 0) {
          const [deploy, raw] = await this.casperClient.getDeploy(deployHash);
          if (raw.execution_results.length !== 0) {
            // @ts-ignore
            if (raw.execution_results[0].result.Success) {
              return deploy;
            } else {
              // @ts-ignore
              throw Error(
                "Contract execution: " +
                  // @ts-ignore
                  raw.execution_results[0].result.Failure.error_message
              );
            }
          } else {
            i--;
            await this.sleep(1000);
            continue;
          }
        }
        throw Error("Timeout after " + i + "s. Something's wrong");
    }

    private sleep = (ms: number) => {
        return new Promise((resolve) => setTimeout(resolve, ms));
    };

Last updated