Skip to content

Latest commit

 

History

History
116 lines (98 loc) · 3.21 KB

pokemon-nft-demo.md

File metadata and controls

116 lines (98 loc) · 3.21 KB
description
Pokemon NFT demo and experiment. 🪙

Pokemon NFT Demo

Valid transactions

NFT1-Group & NFT1-Child contract.

pragma cashscript ^0.6.0;

contract Pokemon(bytes20 owner) {
    // Require pk to match stored owner and signature to match
    function reclaim(pubkey pk, sig s) {
        require(hash160(pk) == owner);
        require(checkSig(s, pk));
    }

    function createNFTChild(pubkey pk, sig s) {
        require(hash160(pk) == owner);
        require(checkSig(s, pk));
    }

    /**
    * Can only be called by the creater of the contract.
    */
    function createNFTGroup(
        pubkey pk,
        sig s,
        bytes20 recipientPkh,
        string actionType,
        string symbol,
        string name,
        string documentURI,
        string documentHash,
        int minerFee,
    ) {  

        require(hash160(pk) == owner);
        require(checkSig(s, pk));

        bytes announcement = new OutputNullData([
            0x534c5000,
            0x81,
            bytes(actionType),
            bytes(symbol),
            bytes(name),
            bytes(documentURI),
            bytes(documentHash),
            0x00,
            0xff, // Trick: Keep this number above the number of transactions you would expect.
            0x0000000000001388
        ]);

        int dust = 546;
        int changeAmount = int(bytes(tx.value)) - dust - minerFee;

        if (changeAmount >= minerFee) {
            bytes34 recipient = new OutputP2PKH(bytes8(dust), recipientPkh);
            bytes32 change = new OutputP2SH(bytes8(changeAmount), hash160(tx.bytecode));
            require(hash256(announcement + recipient + change) == tx.hashOutputs);
        } else {
            require(hash256(announcement) == tx.hashOutputs);
        }
    }
}

Usage

const tx = await contract.functions
  .createNFTGroup(
    alicePk,
    new SignatureTemplate(alice),
    alicePkh,
    actionType,
    symbol,
    name,
    documentURI,
    documentHash,
    minerFee
  )
  .withOpReturn([
    lokadId,
    tokenType,
    actionType,
    symbol,
    name,
    documentURI,
    documentHash,
    decimals,
    baton,
    initialQuantity
  ])
  .withHardcodedFee(minerFee)
  .to(slpRecipient, dust)
  .to(contract.address, change)
  .send();

Meep Debugging

****https://explorer.bitcoin.com/bch/tx/dc8cbc6486709dea0f23db356549a23d53714a1845172c034fec201cd55c203f