# 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.

```solidity
// 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**.

```bash
git clone https://github.com/trustlesscomputer/smart-contract-examples.git
```

## Compile the contracts

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

```bash
cd smart-contract-examples
npm install
npx hardhat compile
```

## Deploy the contracts

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

```js
  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`.

```bash
npx hardhat deploy --tags Ordinals
```

{% hint style="warning" %}
Make sure the accounts in hardhat.config.ts have some $BVM.
{% endhint %}

## 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.

```bash
# 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>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bvm.network/bvm/bitcoin-dapps/evm-code-tutorials/build-an-ordinals-alternative.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
