# Bash & cURL

## Introduction

This example demonstrates how to create a transaction with [CIP-20](https://cips.cardano.org/cip/CIP-20) metadata using the Anvil API. CIP-20 provides a standardized way to include human-readable messages in Cardano transactions using metadata label 674.

For more information about transactions, please refer to the [Transaction Overview](https://github.com/Cardano-Forge/anvil-api/blob/main/docs/guides/transaction/transaction/README.md).

## Objectives

This example creates a transaction with a CIP-20 compliant message on the Preprod network.

## Requirements

* A Cardano wallet with ADA
* A valid API key
* Bash shell environment

## API Request Structure

### Payload Format

```json
{
  "changeAddress": "addr_sender...",
  "message": "Your message" // String or array of strings
}
```

## Message Format Options

### Single String Message

```json
{
  "changeAddress": "addr_sender...",
  "message": "Receipt 42"
}
```

### Array of Strings

```json
{
  "changeAddress": "addr_sender...",
  "message": ["Receipt 42", "Minted by Anvil"]
}
```

### Auto-split for Long Messages

For messages exceeding 64 bytes, the API automatically splits them:

```json
{
  "changeAddress": "addr_sender...",
  "message": "A very long message to demonstrate the auto-split feature. I need more words"
}
```

**Will be formatted as:**

```json
{
  "msg": [
    "A very long message to demonstrate the auto-split feature. I nee",
    "d more words"
  ]
}
```

## Implementation

### Configuration and Parameters (using Bash and cURL)

*Using a preprod wallet for the transaction*

{% code overflow="wrap" %}

```sh
ADDRESS="addr_test1qrvx8wgdndrk98qf62vka3q4fglchk7h940vepdtgcv9fuu0e0aeuac6j2xhz77esaaudku68ha89qesqvd29pmuzw6qk8xkcn"
# See Authentication page for API key details.
X_API_KEY="testnet_EyrkvCWDZqjkfLSe1pxaF0hXxUcByHEhHuXIBjt9"
API_URL="https://preprod.api.ada-anvil.app/v2/services"
```

{% endcode %}

### API Call (using cURL)

Basic POST call with cURL

{% code overflow="wrap" %}

```sh
curl -XPOST \
    -H "Content-Type: application/json" \
    -H "X-Api-Key: ${X_API_KEY}" \
    -d '{"changeAddress": "'${ADDRESS}'", "message":["Receipt 42", "2025-01-24"]}' \
    ${API_URL}/transactions/build
```

{% endcode %}

### Expected Output

{% code overflow="wrap" %}

```json
{
  "hash": "28bdc13d5f532a10347f9671e5d3cd1aae9fae6a760e96808902f7e0baba878e",
  "complete": "84a500d9010281825820022ddfa716301851bb582acb30ff6d8be5718ea9565b87d0be70e5615a77a7cd01018182583900d863b90d9b47629c09d2996ec4154a3f8bdbd72d5ecc85ab461854f38fcbfb9e771a928d717bd9877bc6db9a3dfa728330031aa2877c13b41a1de152f0021a0003cb31031a04e44f940758201bd3787203ca834841a6e263f524989c7a2d8d340ae67098cc9ee225e7bb5df2a0f5a11902a2a1636d7367826a526563656970742034326a323032352d30312d3234",
  "stripped": "84a500d9010281825820022ddfa716301851bb582acb30ff6d8be5718ea9565b87d0be70e5615a77a7cd01018182583900d863b90d9b47629c09d2996ec4154a3f8bdbd72d5ecc85ab461854f38fcbfb9e771a928d717bd9877bc6db9a3dfa728330031aa2877c13b41a1de152f0021a0003cb31031a04e44f940758201bd3787203ca834841a6e263f524989c7a2d8d340ae67098cc9ee225e7bb5df2a0f5f6",
  "witnessSet": "a0",
  "auxiliaryData": "a11902a2a1636d7367826a526563656970742034326a323032352d30312d3234"
}
```

{% endcode %}

## The Whole Script (Bash Version)

<details>

<summary>cip-20.sh</summary>

{% code overflow="wrap" %}

```sh
#!/bin/bash

# Run with: bash cip-20.sh

ADDRESS="addr_test1qrvx8wgdndrk98qf62vka3q4fglchk7h940vepdtgcv9fuu0e0aeuac6j2xhz77esaaudku68ha89qesqvd29pmuzw6qk8xkcn"
# See Authentication page for API key details.
X_API_KEY="testnet_EyrkvCWDZqjkfLSe1pxaF0hXxUcByHEhHuXIBjt9"
API_URL="https://preprod.api.ada-anvil.app/v2/services"

curl -XPOST \
    -H "Content-Type: application/json" \
    -H "X-Api-Key: ${X_API_KEY}" \
    -d '{"changeAddress": "'${ADDRESS}'", "message":["Receipt 42", "2025-01-24"]}' \
    ${API_URL}/transactions/build
```

{% endcode %}

</details>
