# Non Fungible Token (NFT)

# Smart Contract

Our example class for a non-fungible token only has two properties name and symbol. It has one function transfer that updates the _owners property.

class NFT extends Contract {
  constructor(name = '', symbol = '') {
    super({ name, symbol })
  }

  transfer(to: string) {
    this._owners = [to]
  }
}

# Usage

To create a non-fungible token you can call the new function as shown below. The faucet function funds the sender object when the sender object is configured to regtest. The sender.new function mints a new NFT and the transfer function send the NFT to another user.

// Create the sender wallet
const sender = new Computer()

// Fund the senders wallet
await sender.faucet(0.001e8)

// Create a new NFT
const nft = await sender.new(NFT, ['name', 'symbol'])

// Send the NFT
await nft.transfer(new Computer().getPublicKey())

If more than one NFT are broadcast one can save transaction fees by broadcasting a module containing the NFT smart contract first. The class TCB721 is a helper class for that purpose.

// Create wallet
const sender = new Computer(RLTC)

// Fund wallet
await sender.faucet(0.001e8)

// Create helper object
const tbc721 = new TBC721(sender)

// Deploy smart contract
await tbc721.deploy()

// Mint nft
nft = await tbc721.mint('name', 'symbol')

// Transfer NFT
await tbc721.transfer(nft._id, new Computer().getPublicKey())

# Code

You can find the code here.