example

First instance of MRC-101 protocol, the dark portal (dkpt)

Story

At time 796,144, the legendary Dark Portal opened on the lands of Ethereum. It is said that warriors who pass through this gate can be reborn in the Ordinals universe and retain imprints of their souls from this world. During the process of passing through the gate, warriors also unexpectedly acquire domain power due to temporal disturbances. These powers emit five different colors: gold, orange, purple, blue, and green, depending on their intensity. Research shows that when reaching time 800,000, the Dark Gate will deplete its energy and no longer be able to perform additional soul bindings.

Description

  • Starting from block height 796,144, you can transfer any NFT that complies with the ERC-721 standard from the Ethereum to Ordinals.

  • All transmigrated NFTs, in addition to retaining their original metadata, will randomly acquire an additional attribute. This attribute is categorized into five rarity levels: gold, orange, purple, blue, and green.

  • After block height 800,000, it is not possible to obtain soul binding anymore.

If there is any discrepancy between above textual description and the actual results of the code, the results of the code should be considered authoritative.

Deployment

protocol inscription

{
    "p": "mrc-101",
    "op": "deploy",
    "tick": "dkpt",
    "meta": {
        "name":"The dark portal",
        "desc":"the first instance of mrc-721",
        "traits":"color",
        "from":"eth",
        "portal":"0x5BC6b78E70e0e28F9b6Ed3FC1bA3Afaf366A4aC7"
    },
    "code": {
        "engine": "trino",
        "version": "400",
        "body": "with inputs as( select block_height, tx_id, array_join(witness_data,',') payload from bitcoin.inputs t where t.block_height>=796144 and t.block_height<800000 and t.index=0), txns as ( select t.id txid, t.index from bitcoin.transactions t where t.block_height>=796144 and t.block_height<800000 ), output as ( select address as miner, tx_id as txid from bitcoin.outputs t where t.block_height>=796144 and t.block_height<800000 and index = 0 ), rawdata as ( SELECT '{' || from_utf8( from_hex( substr( payload, position('2270223a226d72632d313031' in payload), position('7d68' in payload) - position('2270223a226d72632d313031' in payload) ) ) ) || '}' as body, block_height, t.tx_id as txid FROM inputs t WHERE 1=1 AND t.payload LIKE '%0063036f726401%' AND t.payload LIKE '%2270223a226d72632d313031%' AND t.payload LIKE '%227469636b223a22646b707422%' ), formatted as ( select *, COALESCE(TRY(JSON_PARSE(body)), NULL) as data from rawdata ), parsed as ( SELECT t.txid, block_height, json_extract_scalar(t.data, '$.p') as p, json_extract_scalar(t.data, '$.tick') as tick, json_extract_scalar(t.data, '$.op') as op, json_extract_scalar(t.data, '$.collection') as collection, COALESCE(TRY(CAST (json_extract_scalar(t.data, '$.id') AS bigint)),NULL) as id, COALESCE(TRY(CAST (json_extract_scalar(t.data, '$.bindCode') AS bigint)),NULL) as bind_code, json_extract_scalar(t.data, '$.bindTo') as bind_to FROM formatted t where t.data is not null ), filtered as ( select * from parsed t where t.p='mrc-101' and t.tick='dkpt' and t.op='bind' and t.id is not null and t.bind_code is not null ), integrated as ( select t.*, f.index, o.miner from filtered t join txns f on t.txid=f.txid join output o on t.txid=o.txid ), sequenced as ( select to_hex(txid) as txid,miner,collection,id,bind_code,bind_to, row_number() OVER (PARTITION BY t.collection, t.id, t.bind_code ORDER BY t.block_height ASC,t.index ASC) as seq from integrated t ), binds as ( select *, LENGTH(txid) - LENGTH(REPLACE(txid, '0', '')) AS zero_count from sequenced t where t.seq=1 ), bridge_data as ( select to_hex(t.data) as data from ethereum.logs t where t.contract_address = 0x5BC6b78E70e0e28F9b6Ed3FC1bA3Afaf366A4aC7 and topic0 = 0xb6a08e81716e089c5c6232262b42b5ffb375ec85c31a9ece00b2951f833bce9c and block_number > 17562056 ), b1 as ( select substr(data, 25, 40) as collection, from_base(substr(data, 65, 64), 16) as id, from_base(substr(data, 129, 64), 16) as bind_code, from_base(substr(data, 193, 64), 16) * 2 + 1 as to_offset, from_base(substr(data, 257, 64), 16) * 2 + 1 as name_offset, from_base(substr(data, 321, 64), 16) * 2 + 1 as symb_offset, from_base(substr(data, 385, 64), 16) * 2 + 1 as uri_offset, data from bridge_data ), b2 as ( select *, from_base(substr(data, to_offset, 64), 16) * 2 as to_length, from_base(substr(data, name_offset, 64), 16) * 2 as name_length, from_base(substr(data, symb_offset, 64), 16) * 2 as symb_length, from_base(substr(data, uri_offset, 64), 16) * 2 as uri_length from b1 ), events as ( select collection, id, bind_code, from_utf8( from_hex(substr(data, to_offset + 64, to_length)) ) as miner, from_utf8( from_hex(substr(data, name_offset + 64, name_length)) ) as name, from_utf8( from_hex(substr(data, symb_offset + 64, symb_length)) ) as symbol, from_utf8( from_hex(substr(data, uri_offset + 64, uri_length)) ) as uri from b2 ), souls as ( select f.bind_to as bind, 'eth' as source, t.name, t.symbol, t.uri as tokenUri, json_object('color' : CASE WHEN zero_count>=10 then 'gold' WHEN zero_count=0 or zero_count=9 then 'orange' WHEN zero_count=1 or zero_count=8 then 'piple' WHEN zero_count=2 or zero_count=6 or zero_count=7 then 'blue' WHEN zero_count=3 or zero_count=4 or zero_count=5 then 'green' END ) as traits from events t join binds f on t.miner=f.miner and t.collection=f.collection and t.id=f.id and t.bind_code=f.bind_code )"
    },
    "oops": {
        "bind": "select * from souls"
    }
}

Inscription Number #13701795

portal contract

contract address 0x5BC6b78E70e0e28F9b6Ed3FC1bA3Afaf366A4aC7

Disclaimer

This is just an example and has no commercial value. If you wish to participate, I hope you meet the following requirements.

  1. You have an NFT on Ethereum that complies with the ERC-721 standard, and you are prepared to permanently lost it.

  2. You know how to use tools like Etherscan to interact with smart contracts.

  3. You know how to use tools like Unisats to inscribe inscription.

  4. Confirming that you understand all the contents of this document.

  5. The contract presented in this example may contain potential bugs due to inadequate testing. It is important to acknowledge and accept the associated risks when engaging with it.

If you are certain about participating, please continue reading.

Steps

Below, we will demonstrate how to participate in this experiment by providing a specific example. Here is a check list for the information you need to collect. You can fill c1~c4 before start and you will get v1 after step #2.

aka
desc
value

c1

The contract address of your NFT wants to transmigrate.

you fill

c2

The id of your NFT.

you fill

c3

The BTC address you use to receive the Bind inscription.

you fill

c4

Just type a random number to keep bind inscription unique.

you fill

c5

portal contract address

0x5BC6b78E70e0e28F9b6Ed3FC1bA3Afaf366A4aC7

v1

The Inscription id of your Target inscription.

collect after #2.

#1 Prepare a source NFT

In this example, I choose to use my Vogu#129 to demonstrate how to participate in this experiment. Here are some basic information about Vogu#129.

If you already find out c1 and c2, you can skip this step.

You need find the following value of your NFT.

key
aka
value (e.g)

Contract address

c1

0x18c7766A10df15Df8c971f6e8c1D2bbA7c7A410b

Token id

c2

caution, your will lost this NFT permanently after transmigration.

#2 Inscribe Target Inscription

This inscription was inscribed using LooksOrdinal from an image file. In order to reduce the inscription cost, I have modified the resolution of the image. Of course, as mentioned before, this inscription determines the appearance of your NFT, and you can decide what content to inscribe. After inscription, we can get the inscription id for later usage.

If you decide to use a previous inscription you have, just fill the inscription id to v1 and skip this step.

You can get the following value of your inscription.

key
aka
value (e.g)

inscrpiton id

v1

bacf05d627b53c28d65f83982b3a6e0ff5d5668130f00e388c3878c47f561a7ci0

#3 Prepare Bind Inscription

After block height 796,144, I will use the following data to inscribe my "Bind inscription".

Firstly, you need prepare an address to receive this inscription.

key
aka
value (e.g)

address

c3

bc1q7d8t5qv9hu7284t9fzx85e996fl426euu6qzlm

Then you can use tools like LooksOrdinal to inscribe the "Bind inscription" to above address.

{
    "p": "mrc-101",
    "tick": "dkpt",
    "op": "bind",
    "collection": "0x18c7766A10df15Df8c971f6e8c1D2bbA7c7A410b",
    "id": "129",
    "bindCode": "1",
    "bindTo": "bacf05d627b53c28d65f83982b3a6e0ff5d5668130f00e388c3878c47f561a7ci0"
}
key
aka
value (e.g)

collection

c1

0x18c7766A10df15Df8c971f6e8c1D2bbA7c7A410b

id

c2

129

bindTo

v1

bacf05d627b53c28d65f83982b3a6e0ff5d5668130f00e388c3878c47f561a7ci0

bindCode

c4

1

Please use the following compressed json format to inscribe.

{"p":"mrc-101","tick":"dkpt","op":"bind","collection":"0x18c7766A10df15Df8c971f6e8c1D2bbA7c7A410b","id":"129","bindCode":"1","bindTo":"bacf05d627b53c28d65f83982b3a6e0ff5d5668130f00e388c3878c47f561a7ci0"}

Don't forget to set the collection, id, bindCode, and bindTo to your own values. Please ensure that you replace them accordingly.

#4 Approve Transaction

In order for the "Portal contract" to be able to destroy your NFT on Ethereum, please set the "Portal contract" as the handler for your "Source NFT".

key
aka
value (e.g)

to

c5

0x5BC6b78E70e0e28F9b6Ed3FC1bA3Afaf366A4aC7

tokenId

c2

129

Please make sure you have completed the above steps before transmigration. Then please redirect to link and fill the following column and then click write to send the transaction.

key
aka
value (e.g)

collection

c1

0x18c7766A10df15Df8c971f6e8c1D2bbA7c7A410b

id

c2

129

to

c3

bc1q7d8t5qv9hu7284t9fzx85e996fl426euu6qzlm

bindCode

c4

1

Verification

FAQ

After my soul is bound to a particular inscription, is it possible to rebind it?

  • The current data model does not support rebinding due to the lack of information about the inscription's position. It is possible that future upgraded versions of the protocol may support this feature. However, to rebind, you must at least be the owner of the inscription.

Code

with inputs as (
    select block_height, tx_id, array_join(witness_data,',') payload 
    from 
    bitcoin.inputs t 
    where t.block_height>=796144 and t.block_height<800000 and t.index=0
),
txns as (
    select t.id txid, 
    t.index 
    from  bitcoin.transactions t 
    where t.block_height>=796144 and t.block_height<800000
),
output as (
    select address as miner,
        tx_id as txid
    from bitcoin.outputs t
    where t.block_height>=796144 and t.block_height<800000 and index = 0
),
rawdata as (
    SELECT 
        '{' || from_utf8(
            from_hex(
                substr(
                    payload,
                    position('2270223a226d72632d313031' in payload),
                    position('7d68' in payload) - position('2270223a226d72632d313031' in payload)
                )
            )
        ) || '}' as body,
        block_height,
        t.tx_id as txid
    FROM inputs t
    WHERE 1=1
        AND t.payload LIKE '%0063036f726401%'
        AND t.payload LIKE '%2270223a226d72632d313031%'
        AND t.payload LIKE '%227469636b223a22646b707422%'
),
formatted as (
    select *, COALESCE(TRY(JSON_PARSE(body)), NULL) as data from rawdata
),
parsed as (
    SELECT t.txid,
        block_height,
        json_extract_scalar(t.data, '$.p') as p,
        json_extract_scalar(t.data, '$.tick') as tick,
        json_extract_scalar(t.data, '$.op') as op,
        json_extract_scalar(t.data, '$.collection') as collection,
        COALESCE(TRY(CAST (json_extract_scalar(t.data, '$.id') AS bigint)),NULL) as id,
        COALESCE(TRY(CAST (json_extract_scalar(t.data, '$.bindCode') AS bigint)),NULL) as bind_code,
        json_extract_scalar(t.data, '$.bindTo') as bind_to
    FROM formatted t
    where t.data is not null
),
filtered as (
    select * from parsed t where t.p='mrc-101' and t.tick='dkpt' and t.op='bind' and t.id is not null and t.bind_code is not null
),
integrated as (
    select 
    t.*, f.index, o.miner from filtered t 
    join 
    txns f on t.txid=f.txid
    join
    output o on t.txid=o.txid
),
sequenced as (
    select 
        to_hex(txid) as txid,miner,collection,id,bind_code,bind_to,
        row_number() OVER (PARTITION BY t.collection, t.id, t.bind_code ORDER BY t.block_height ASC,t.index ASC) as seq
    from 
        integrated t
),
binds as (
    select *, LENGTH(txid) - LENGTH(REPLACE(txid, '0', '')) AS zero_count from sequenced t where t.seq=1
),
bridge_data as (
    select to_hex(t.data) as data
    from ethereum.logs t
    where t.contract_address = 0x5BC6b78E70e0e28F9b6Ed3FC1bA3Afaf366A4aC7
        and topic0 = 0xb6a08e81716e089c5c6232262b42b5ffb375ec85c31a9ece00b2951f833bce9c
        and block_number > 17562056
),
b1 as (
    select substr(data, 25, 40) as collection,
        from_base(substr(data, 65, 64), 16) as id,
        from_base(substr(data, 129, 64), 16) as bind_code,
        from_base(substr(data, 193, 64), 16) * 2 + 1 as to_offset,
        from_base(substr(data, 257, 64), 16) * 2 + 1 as name_offset,
        from_base(substr(data, 321, 64), 16) * 2 + 1 as symb_offset,
        from_base(substr(data, 385, 64), 16) * 2 + 1 as uri_offset,
        data
    from bridge_data
),
b2 as (
    select *,
        from_base(substr(data, to_offset, 64), 16) * 2 as to_length,
        from_base(substr(data, name_offset, 64), 16) * 2 as name_length,
        from_base(substr(data, symb_offset, 64), 16) * 2 as symb_length,
        from_base(substr(data, uri_offset, 64), 16) * 2 as uri_length
    from b1
),
events as (
    select collection,
        id,
        bind_code,
        from_utf8(
            from_hex(substr(data, to_offset + 64, to_length))
        ) as miner,
        from_utf8(
            from_hex(substr(data, name_offset + 64, name_length))
        ) as name,
        from_utf8(
            from_hex(substr(data, symb_offset + 64, symb_length))
        ) as symbol,
        from_utf8(
            from_hex(substr(data, uri_offset + 64, uri_length))
        ) as uri
    from b2
),
souls as (
    select f.bind_to as bind, 
        'eth' as source,
        t.name,
        t.symbol,
        t.uri as tokenUri,
        json_object('color' : 
            CASE 
                WHEN zero_count>=10 then 'gold'
                WHEN zero_count=0 or zero_count=9 then 'orange'
                WHEN zero_count=1 or zero_count=8 then 'piple'
                WHEN zero_count=2 or zero_count=6 or zero_count=7  then 'blue'
                WHEN zero_count=3 or zero_count=4 or zero_count=5  then 'green'
            END
        ) as traits
    from events t join binds f
        on t.miner=f.miner
        and t.collection=f.collection
        and t.id=f.id
        and t.bind_code=f.bind_code
)
select * from souls

Last updated