Build an Ordinals alternative
Let's implement a simplified version of the Ordinals Protocol from scratch with Bitcoin Virtual Machine.
- create an inscription 
- retrieve an inscription 
- send an inscription 
- buy and sell inscriptions 
Write an Ordinals Protocol smart contract
It turns out that writing an Ordinals Protocol smart contract is very simple; all it is is a file storage system inside the Bitcoin network. Here is a basic contract to provide an Ordinals-like inscription system on Bitcoin Virtual Machine.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract Ordinals is ERC721 {
        using Counters for Counters.Counter;
        Counters.Counter private _inscriptionNumbers;
        mapping(uint256 => bytes) public inscriptions;
        constructor() ERC721("Ordinals", "ORD") {}
        function inscribe(address owner, bytes memory inscription) 
                public 
                returns (uint256) 
        {
                uint256 num = _inscriptionNumbers.current();
                _mint(owner, num);
                inscriptions[num] = inscription;
                _inscriptionNumbers.increment();
                return num;
        }
}Extending ERC-721, we only need to implement the inscribe() function to create an inscription as an NFT. Sending and receiving an inscription is now as simple as sending and receiving an NFT. You can also trade the inscription on open markets since it's an ERC-721.
Clone the smart contract examples
We've prepared a few different examples for you to get started. The Ordinal Theory example is located at smart-contract-examples/contracts/Ordinals.sol.
git clone https://github.com/trustlesscomputer/smart-contract-examples.gitCompile the contracts
To compile your contracts, use the built-in hardhat compile task.
cd smart-contract-examples
npm install
npx hardhat compileDeploy the contracts
Review config file hardhat.config.ts. The network configs should look like this.
  networks: {
    mynw: {
      url: "http://localhost:10002",
      accounts: {
        mnemonic: "<your mnemonic with funds>"
      },
      timeout: 100_000,
    },
    blockscoutVerify: {
      blockscoutURL: "http://localhost:4000", // your explorer URL
      ...
    }
  }Run the deploy scripts using hardhat-deploy.
npx hardhat deploy --tags OrdinalsMake sure the accounts in hardhat.config.ts have some $BVM.
Interact with the contracts
Once the contracts are deployed, you can interact with them. We've prepared a few hardhat tasks to make it easy for you to interact with the contracts.
# create an inscription
npx hardhat ord-inscribe --data <raw-hex>
# your new inscriptions will be given id=0,1,...
# read an inscription
npx hardhat ord-read --id <inscription-number>Last updated
