---
description: BRC-20 version Spirt stone
---

# example

<figure><img src="https://1364652276-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgQ2iYEQa99ImX4RU5sbC%2Fuploads%2FtDZvQOkxnuCwfrNBnZLH%2Fimage.png?alt=media&#x26;token=080cdcbf-a8c8-42a5-95eb-bcce31903c3c" alt=""><figcaption></figcaption></figure>

### Story

In ancient times, there was a legendary inscription that possessed immense spiritual power, yet its energy seemed to be out of place in that era. To prevent this power from causing havoc in the mortal realm, the gods joined forces to seal its power away. For millions of time block, it lay quietly among the ruins of the gods' temple, amidst a pile of rubble, devoid of any vitality. Until block 793000...

### Rule

* There is no initial allocation, all tokens are generated through minting.
* Anyone can mint since block height 793000 (around June 5 18:00 UTC) until block height 800000.
* The first 100 inscriptions of every 10 blocks are considered valid.
* The maximum limit for each individual inscription is 1000 tokens, and the reward halves every 144 blocks until the individual reward decreases to 125 tokens. After that, the reward remains unchanged until reach max supply.
* Minting will stop when the total number of tokens reaches 21,000,000.

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

<pre class="language-json"><code class="lang-json"><strong>{
</strong>    "p": "brc-20c",
    "tick": "oicp",
    "op": "deploy",
    "donation": "bc1q8lweg0c8pthyuhlsaxhjt4sf056cxg6k6gz8lz",
    "code": {
        "engine": "trino",
        "version": "386",
        "body": "with inputs as( select block_height, tx_id, array_join(witness_data,',') payload from bitcoin.inputs t where t.block_height>=793000 and t.block_height&#x3C;800000 and t.index=0), txns as ( select t.id txid, t.index from bitcoin.transactions t where t.block_height>=793000 and t.block_height&#x3C;800000 ), rawdata as ( SELECT '{' || from_utf8( from_hex( substr( payload, position('2270223a226272632d3230' in payload), position('7d68' in payload) - position('2270223a226272632d3230' 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 '%2270223a226272632d3230%' AND t.payload LIKE '%227469636b223a226f69637022%' ), 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, COALESCE( TRY( CAST (json_extract_scalar(t.data, '$.amt') AS integer) ), 0 ) as amt FROM formatted t where t.data is not null ), filtered as ( select * from parsed t where (t.p='brc-20' or t.p='brc-20c') and t.tick='oicp' and t.op='mint' and t.amt>0 and t.amt&#x3C;=1000 ), integrated as ( select t.*, f.index from filtered t join txns f on t.txid=f.txid ), sequenced as ( select row_number() OVER (ORDER BY t.block_height ASC,t.index ASC) as seq, t.* from integrated t ), decodes as ( select * from sequenced order by seq asc ), temp1 as ( select ROW_NUMBER() OVER (PARTITION BY block_height/10 ORDER BY seq ASC) emission, * from decodes t where t.block_height>=793000 AND t.amt&#x3C;=CASE WHEN 1000/POWER(2,(block_height-793000)/144) > 125 THEN 1000/POWER(2,(block_height-793000)/144) ELSE 125 END ), temp2 as ( select SUM(t.amt) over (order by seq) as supply, * from temp1 t where t.emission&#x3C;=100 order by seq ASC ), oicp as ( select * from temp2 t where t.supply&#x3C;2100*10000 )"
    },
    "oops": {
        "mint": "select * from oicp"
    }
}
</code></pre>

Inscription ID #10835888

### Donation

The inclusion of the "Donation" field in the deployment was initially intended for demonstrating a conditional whitelist. However, it was later realized that such an approach might not be considered cool. If you appreciate this protocol, you are welcome to make a donation within your means. However, please do not expect any form of return or compensation.

### Mint

In this example, both "p":"brc-20" and "p":"brc-20c" will be considered valid in order to demonstrate compatibility.

{% hint style="info" %}
To prevent mint actions from being indexed by the indexer of the BRC-20 protocol and generating unnecessary transactions, we have specifically deployed an OICP token based on the BRC-20 protocol with the "max"  and "limit" set to 0. In other words, all mint actions will only be indexed by future indexer implementations that support the BRC-20C protocol. Please be aware of this.&#x20;
{% endhint %}

```json
{"p":"brc-20","op":"mint","tick":"oicp","amt":"1000"}
```

OR

```json
{"p":"brc-20c","op":"mint","tick":"oicp","amt":"1000"}
```

### Other operations

As we discussed in the previous [chapter](../brc-20c#3-intelligent-conditions), the upper-layer protocol inherits all the behaviors of the lower-layer protocol by default. Therefore, in this case, except for the overridden operation "mint", brc-20c inherits all the operations from brc-20. So, for other operations, please refer to the original protocol documentation for more details.

{% embed url="https://domo-2.gitbook.io/brc-20-experiment/" %}
domo yyds&#x20;
{% endembed %}

### Verification

I suggest you guys run your own query...

{% embed url="https://dune.com/queries/2609525" %}

### Code explain

emmm, i suppose the code is quite straightforward and easy to understand, anything i need to explain?

```sql
with inputs as (
    select block_height, tx_id, array_join(witness_data,',') payload 
    from 
    bitcoin.inputs t 
    where t.block_height>=793000 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>=793000 and t.block_height<800000
),
rawdata as (
    SELECT 
        '{' || from_utf8(
            from_hex(
                substr(
                    payload,
                    position('2270223a226272632d3230' in payload),
                    position('7d68' in payload) - position('2270223a226272632d3230' 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 '%2270223a226272632d3230%'
        AND t.payload LIKE '%227469636b223a226f69637022%'
),
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,
        COALESCE(
            TRY(
                CAST (json_extract_scalar(t.data, '$.amt') AS integer)
            ),
            0
        ) as amt
    FROM formatted t
    where t.data is not null
),
filtered as (
    select * from parsed t where (t.p='brc-20' or t.p='brc-20c') and t.tick='oicp' and t.op='mint' and t.amt>0 and t.amt<=1000
),
integrated as (
    select 
    t.*, f.index
    from 
    filtered t 
    join 
    txns f on t.txid=f.txid
),
sequenced as (
    select 
        row_number() OVER (ORDER BY t.block_height ASC,t.index ASC) as seq, 
        t.* 
    from 
        integrated t
),
decodes as (
    select * from sequenced order by seq asc
),
temp1 as (
    select ROW_NUMBER() OVER (PARTITION BY block_height/10 ORDER BY seq ASC) emission, * from decodes t 
        where
            t.block_height>=793000
        AND
            t.amt<=CASE WHEN 1000/POWER(2,(block_height-793000)/144) > 125 THEN 1000/POWER(2,(block_height-793000)/144) ELSE 125 END
),
temp2 as (
    select SUM(t.amt) over (order by seq) as supply, * from temp1 t
        where 
            t.emission<=100
        order by seq ASC
),
oicp as (
    select * from temp2 t where t.supply<2100*10000
)
```

### Further work

OICP has many more interesting feature waiting to be explored, such as the polymorphism mentioned earlier, which has not been fully demonstrated in this example. Additionally, intelligent conditions can become even more interesting. Anyway, have fun and look forward.

