Skip to content

Latest commit

 

History

History
144 lines (102 loc) · 3.5 KB

File metadata and controls

144 lines (102 loc) · 3.5 KB

Haiku Contract Testing Guide

🎯 Contract Successfully Deployed!

Contract Details:

  • Address: ST2EX94QMG4FEHYV9KRJRX9BGM313YJ9DAYKZKWFN
  • Name: haiku-basic
  • Network: Stacks Testnet
  • Status: ✅ Deployed and Ready

🧪 Testing the Contract Functions

Step 1: Get Your Private Key

To test the contract functions, you need your private key (not the mnemonic):

  1. Hiro Wallet:

    • Open Hiro Wallet
    • Go to Settings → Security
    • Export Private Key
    • Copy the private key (starts with letters/numbers)
  2. Xverse Wallet:

    • Open Xverse
    • Go to Settings → Security
    • Export Private Key
    • Copy the private key

Step 2: Test Contract Functions

  1. Update the test script:

    cd backend
    nano test-full-contract.js
  2. Replace YOUR_PRIVATE_KEY_HERE with your actual private key

  3. Uncomment the transaction code in the script

  4. Run the test:

    node test-full-contract.js

Step 3: Manual Testing via Stacks Explorer

You can also test the contract manually:

  1. Visit: https://explorer.stacks.co/contract/ST2EX94QMG4FEHYV9KRJRX9BGM313YJ9DAYKZKWFN.haiku-basic?chain=testnet

  2. Test Functions:

    • initialize - Initialize the contract (call once)
    • fund-stx - Fund contract with STX
    • create-haiku - Create haiku payment
    • claim-with-haiku - Claim payment using haiku
    • emergency-withdraw - Withdraw all funds

🔧 Contract Functions

Initialize Contract

(initialize)
  • Purpose: Initialize the contract (can only be called once)
  • Caller: Contract owner only
  • Cost: ~0.001 STX

Fund Contract

(fund-stx amount)
  • Purpose: Add STX to the contract
  • Parameters: amount (in microSTX)
  • Caller: Funder only
  • Cost: ~0.001 STX + amount

Create Haiku Payment

(create-haiku haiku-hash stx-amount)
  • Purpose: Create a haiku-protected payment
  • Parameters:
    • haiku-hash: SHA-256 hash of the haiku
    • stx-amount: Amount in microSTX
  • Caller: Funder only
  • Cost: ~0.001 STX

Claim Haiku Payment

(claim-with-haiku haiku-hash)
  • Purpose: Claim payment using the correct haiku
  • Parameters: haiku-hash: SHA-256 hash of the haiku
  • Caller: Anyone with correct haiku
  • Cost: ~0.001 STX

Emergency Withdraw

(emergency-withdraw)
  • Purpose: Withdraw all remaining funds
  • Caller: Funder only
  • Cost: ~0.001 STX

📋 Testing Workflow

  1. Initialize the contract (once)
  2. Fund the contract with STX
  3. Create a haiku payment
  4. Claim the payment using the haiku
  5. Test emergency withdrawal

🔗 Useful Links

🎯 Next Steps

After testing the contract functions:

  1. Integrate with Frontend: Connect the frontend to the deployed contract
  2. Test Full Flow: Create haikus through the frontend
  3. Deploy to Mainnet: When ready for production

⚠️ Important Notes

  • Testnet Only: This contract is on testnet - use testnet STX only
  • Private Key Security: Never share your private key
  • Gas Fees: Each transaction costs ~0.001 STX in fees
  • One-Time Init: Contract can only be initialized once