Skip to content

About

A TypeScript implementation of a vesting smart contract using the Cardano blockchain and Anvil API

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Cardano Vesting Smart Contract

A TypeScript implementation of a vesting smart contract using the Cardano blockchain and Anvil API. This project demonstrates how to deploy, lock funds, and unlock funds using a smart contract written in Aiken and interacting with the smart contract using Anvil's API.

Project Structure

vesting-smart-contract/
├── hello-aiken/           # Aiken smart contract
├── scripts/              # Deployment and interaction scripts
│   ├── deploy-contract.ts
│   ├── lock-funds.ts
│   ├── unlock-funds.ts
│   └── check-tx-status.ts
├── src/
│   ├── sdk/             # Core SDK for Anvil API interactions
│   └── utils/           # Utility functions and storage management
└── config/              # Configuration files (keys and environment)

Prerequisites

  • Node.js (v18 or higher)
  • TypeScript
  • Anvil API Key
  • Customer Keys for transaction signing

Setup

  1. Install dependencies:
npm install
  1. Configure environment variables:
    • Copy .env.example to .env
    • Add your Anvil API key:
ANVIL_PREPROD_API_KEY="your-api-key"
CUSTOMER_KEYS_PATH="./config/customer.keys.json"
  1. Configure customer keys:
    • Copy config/customer.keys.example.json to config/customer.keys.json
    • Add your customer keys:
{
  "base_address_preprod": "your-base-address",
  "key_hash": "your-key-hash",
  "skey": "your-signing-key"
}

Available Commands

  • Deploy the smart contract:
npm run deploy
  • Lock funds in the contract:
npm run lock
  • Unlock funds from the contract:
npm run unlock
  • Check transaction status:
npm run check

Smart Contract Details

The smart contract is implemented in Aiken and requires:

  • A specific message ("Hello, Aiken!!") for unlocking
  • Transaction must be signed by the owner specified in the datum
  • Proper validation of redeemer and datum structures

Transaction History

All transactions (lock/unlock) are stored in transaction-history.json for reference and tracking.

Security Notes

  • Never commit sensitive keys or environment variables
  • Always use the preprod network for testing
  • Validate all transaction parameters before submission
  • Keep your API keys secure

Error Handling

The project implements comprehensive error handling:

  • Transaction validation errors
  • API communication errors
  • Smart contract interaction errors
  • Configuration validation

About

A TypeScript implementation of a vesting smart contract using the Cardano blockchain and Anvil API

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages