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.
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)
- Node.js (v18 or higher)
- TypeScript
- Anvil API Key
- Customer Keys for transaction signing
- Install dependencies:
npm install- Configure environment variables:
- Copy
.env.exampleto.env - Add your Anvil API key:
- Copy
ANVIL_PREPROD_API_KEY="your-api-key"
CUSTOMER_KEYS_PATH="./config/customer.keys.json"- Configure customer keys:
- Copy
config/customer.keys.example.jsontoconfig/customer.keys.json - Add your customer keys:
- Copy
{
"base_address_preprod": "your-base-address",
"key_hash": "your-key-hash",
"skey": "your-signing-key"
}- 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 checkThe 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
All transactions (lock/unlock) are stored in transaction-history.json for reference and tracking.
- 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
The project implements comprehensive error handling:
- Transaction validation errors
- API communication errors
- Smart contract interaction errors
- Configuration validation