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.

Compile the contracts

To compile your contracts, use the built-in hardhat compile task.

Deploy the contracts

Review config file hardhat.config.ts. The network configs should look like this.

Run the deploy scripts using hardhat-deploy.

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.

Last updated