# Smart Contracts

## Introduction

The Anvil API provides a comprehensive suite of tools for working with Cardano smart contracts, offering a streamlined experience for developers to deploy, interact with, and manage smart contracts without dealing with the underlying complexity of the Cardano blockchain.

> **Prerequisites**: This guide assumes familiarity with basic Cardano concepts and smart contract development principles. If you're new to Cardano smart contracts, we recommend reviewing [Aiken Fundamentals - EUTxO](https://aiken-lang.org/fundamentals/eutxo) before proceeding.

## Where Anvil Fits in the Cardano Smart Contract Ecosystem

Smart contract development and usage follows a lifecycle from code to on-chain interaction. The diagram below illustrates where Anvil API fits in this process:

<figure><img src="/files/bLEy074Wkb6WMm072OuR" alt="Smart Contract Lifecycle"><figcaption><p>Smart Contract Lifecycle</p></figcaption></figure>

As shown in the diagram, Anvil API comes into play after you've written and compiled your smart contract code with Aiken. Our tools focus on:

* **Blueprint Management**: Storing and managing your compiled smart contract blueprints
* **Deployment**: Saving your contracts to the Cardano blockchain
* **Transaction Building**: Creating the simple or complex transactions needed to interact with contracts
* **Script Execution**: Handling the validation and execution logic upon submit

This clear separation of concerns allows you to focus on writing high-quality contract logic while Anvil handles the complexities of blockchain interaction.

## CIP-57 Blueprint Format

The Anvil API works with [CIP-57 Plutus Blueprint](https://cips.cardano.org/cip/CIP-57) format, which provides a standardized way to describe Cardano smart contracts.

### Blueprint Generation with Aiken

Aiken is the recommended smart contract language for Anvil API. It generates CIP-57 compliant blueprints automatically when you build your project:

```bash
# Generate CIP-57 blueprint file with verbose output for debugging
aiken build --verbose
```

The build process creates a `plutus.json` file in your project's `build` directory, which is a complete CIP-57 blueprint that can be directly used with the Anvil API. Using the `--verbose` flag will provide detailed compilation information and help with debugging.

Once you have your blueprint file, you can use the Anvil API to manage and interact with your smart contracts without having to deal with the low-level details of the Cardano blockchain.

## Working with Smart Contracts

Once you have your blueprint file, you can use the Anvil API to manage and interact with your smart contracts. The Anvil API provides several ways to work with Cardano smart contracts:

### Validator Types and Script Purposes

Cardano smart contracts use validators to define the conditions under which certain operations can occur. Understanding validator types is essential for implementing effective smart contracts.

{% content-ref url="/pages/C4kqFOvI4YfKlVqtozKt" %}
[Validators](/guides/smart-contract/validators.md)
{% endcontent-ref %}

### Blueprint Management

Learn how to store, retrieve, update, and delete your CIP-57 blueprints using the Anvil API.

{% content-ref url="/pages/fLloQsEjlrFZ3GccPWFy" %}
[Blueprint Management (CIP-57)](/guides/smart-contract/blueprint-management.md)
{% endcontent-ref %}

## Example Smart Contract Interactions

To help you get started with smart contracts on Cardano, we provide several example implementations:

### Hello World Smart Contract

A simple smart contract example to help you understand the basics.

{% content-ref url="/pages/EpkvVH55nFmbWpa1IkKS" %}
[Hello World Smart Contract](/guides/smart-contract/hello-world-smart-contract.md)
{% endcontent-ref %}

### Minting Tokens with Smart Contracts

Learn how to create and manage tokens using mint validators.

{% content-ref url="/pages/sIDc3mGeCPs5eUafjqfo" %}
[Mint with Smart Contract](/guides/smart-contract/mint-smart-contract.md)
{% endcontent-ref %}

### Escrow Smart Contract

A complete end-to-end example implementing an escrow system with Next.js, Weld, and Blockfrost Webhooks for real-time updates.

{% content-ref url="/pages/njTW7bu9BDbOptiklPpv" %}
[End-to-End Next.js Escrow Guide](/guides/smart-contract/escrow.md)
{% endcontent-ref %}


---

# 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://dev.ada-anvil.io/guides/smart-contract.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.
