> For the complete documentation index, see [llms.txt](https://docs.teranode.group/nchain-event/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.teranode.group/nchain-event/independent-records/api-workflow/write-record.md).

# Write Record

{% hint style="warning" %}
The record will be submitted to the blockchain asynchronously. You should use GET Location Status to find out whether the record has been confirmed before performing any other operations on the returned location.
{% endhint %}

## **Write Encoded Record**

<figure><img src="/files/yD6RcxRI42Isg0R4tMIG" alt="" width="563"><figcaption></figcaption></figure>

1. The record owner selects any encoders and salt to use
2. The record owner writes a record to be encoded via nChain Event
3. nChain Event encodes the record as specified to produce a fingerprint
4. The fingerprint is written to the blockchain
5. The result is the fingerprint and its location on the blockchain
6. The record owner stores the encoder, salt, fingerprint and location for subsequent processing

#### Example code:

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST "$URL/api/v1/records?encode=SHA256(01-02T13.14.15)|Base64" \
     -H "x-api-key: $KEY" \
     -H "Content-Type: application/octet-stream" \
     --data-binary "hello"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('${url}/api/v1/records?encode=SHA256(01-02T13.14.15)|Base64', {
  method: 'POST',
  headers: {
    'x-api-key': '${key}',
    'Content-Type': 'application/octet-stream'
  },
  body: 'hello'
});
```

{% endtab %}
{% endtabs %}

#### Example cURL response:

```json
{
  "txId": "7d2aef40841f0109....c31c83a5505a4c147e",
  "encoding" : [
    { 
      "content-type": "....SHA256....|Base64", 
      "output" : "ytfc5c5wv0V7hOo....G1ucRFzSIe6rw=" 
    }
  ]
  ...
}
```

The final "output" shows the record that was written to the blockchain.

## Write Unencoded Record ‡

<figure><img src="/files/UhnkkRd5bWCIjg3MlWLb" alt="" width="375"><figcaption></figcaption></figure>

1. The record owner writes an unencoded record via nChain Event
2. The result is the location of the record on the blockchain
3. The record owner stores the location for later processing

#### **Example code:**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST $URL/api/v1/records \
     -H "x-api-key: $KEY" \
     -H "Content-Type: application/octet-stream" \
     --data-binary "hello"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('${url}/api/v1/records', {
  method: 'POST',
  headers: {
    'x-api-key': '${key}',
    'Content-Type': 'application/octet-stream'
  },
  body: 'hello'
});
```

{% endtab %}
{% endtabs %}

#### Example cURL response:

```json
{
  "txId": "7d2aef40841f0109....c31c83a5505a4c147e"
}
```

## Extract Location

At least the location (shown as "txId") should be stored for subsequent operations:

{% tabs %}
{% tab title="cURL" %}

```bash
LOC=7d2aef40841f0109....c31c83a5505a4c147e
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const data = await response.json();
const loc = data.txId;
```

{% endtab %}
{% endtabs %}
