Hello World Smart Contract

2025-02-21: Missing steps for lock and unlock

Requirements

  • A Cup of Coffee

  • The Aiken Hello World Example (You need to update the smart contract name to avoid getting the already exists message from Anvil API.)

    • The Smart Contract name should be in this format: your_org/hello-world

    • See the official documentation: Aiken Hello World

  • An Anvil API Key (you can use the one provided in this document to access preprod)

  • customer.json with 100ADA, you can use the CLI tool to generate the wallet, then send funds from the faucet to it. (Wallet CLI)


Objectives

Interact with any Smart Contracts using Anvil API

Objectives

  • Upload Blueprint

  • Deploy Smart Contract On-Chain

  • Update/Delete Blueprint

  • Hello World Lock & Unlock ADA

  • Get a jsonSchema from your blueprint to get types for the language you use.

  • See below for the code in one file (full.ts)


Aiken Smart Contract

Smart Contract - Update Name

aiken.toml

Helper Functions

Function to extract validator hashes from a blueprint


Prerequisites

You need to load your Blueprint like this:

The wallet used in this guide is loaded like this:

You also need the CSL imports and Buffer for that to work, it is only the case when you are using the wallet in the backend.

You can use any wallet, like the one in your browser or with weld, but to limit the external steps and streamline the flow. This guide uses the wallet directly in the backend. You can take a look at the signing transaction document to see how to use the browser wallet.

The api key used is this one:


Payload

To upload your validator on Anvil Backend

Benefit of doing so, will reduce the complexity and steps to interact with your smart contract. as it will be store directly in the backend. Your API Key is link with your Blueprint and will let you update and delete it if needed.

Deploy the Smart Contract On-Chain

  • scriptAddresses:

    • Key = Validator Hash

    • Value = Address of the Smart Contract (Enterprise Address)


Steps

Step 1 - Upload Blueprint

Upload your blueprint (plutus.json) to Anvil Backend

Create Blueprint

  • scriptAddresses: Needed for Step #2

This API Call is an upsert, so if you forget the scriptAddresses or need to update your blueprint, you can reuse the same call.

Tip: Once registered, if you need to update the name without changing the smart contract code or logic, you can safely delete the blueprint using the former name and then re-upload it.

Step 2 - Deploy Smart Contract

You need a valid Cardano wallet with some ADA on it (100ADA should be more than enough) Wallet CLI

Deploy the smart contract on-chain in order to get the reference UTXO

Payload to build the transaction:

Create the transaction

Sign and Submit the transaction

The signature process uses CSL for simplicity. For more information, see the Signing a Transaction guide.

Update blueprint to link references to deployed validators.

Conclusion

From here you have uploaded your blueprint and linked the reference UTXO on-chain and in Anvil Backend.

The next step is to interact with the hello-world Smart Contract (Lock & Unlock ADA)


Full Example

full.ts

Usage (Hello World Lock/Unlock)

Lock Funds

Payload

TODO: Explain the JSON below

Unlock Funds

Payload

TODO: Explain the JSON below

Full Example - Lock Fund

lock.ts

Full Example - Unlock Fund

unlock.ts

Last updated

Was this helpful?