Skip to main content

Installation

This guide will help you set up the Hoosat Motoko package in your Internet Computer project.

Prerequisites

Before installing Hoosat-mo, ensure you have:

  • DFX SDK (0.15.0 or higher) - Internet Computer development toolkit
  • Mops - Motoko package manager
  • Node.js (18.0 or higher) - For running DFX commands
  • Basic Motoko knowledge - Familiarity with Motoko syntax

Install DFX

If you haven't installed DFX yet:

sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"

Verify installation:

dfx --version
# Output: dfx 0.15.0 or higher

Install Mops

Install the Motoko package manager globally:

npm install -g ic-mops

Verify installation:

mops --version

Installation Methods

If you already have a Motoko project:

  1. Navigate to your project directory:
cd your-project
  1. Add Hoosat-mo package:
mops add hoosat-mo
  1. Configure dfx.json:

Add the following to your dfx.json under defaults.build.packtool:

{
"defaults": {
"build": {
"packtool": "mops sources"
}
}
}
  1. Install dependencies:
mops install
  1. Import in your Motoko code:
import Wallet "mo:hoosat-mo/wallet";
import Address "mo:hoosat-mo/address";
import Transaction "mo:hoosat-mo/transaction";
import Types "mo:hoosat-mo/types";

Method 2: Clone Example Project

Start with a working example:

  1. Clone the repository:
git clone https://github.com/Hoosat-Oy/Hoosat-mo.git
cd Hoosat-mo
  1. Install dependencies:
mops install
  1. Start local replica:
dfx start --background
  1. Deploy the example canister:
dfx deploy
  1. Test the deployment:
dfx canister call hoosat_ecdsa get_hoosat_address '(null)'

Project Structure

After installation, your project should look like:

your-project/
├── dfx.json # DFX configuration
├── mops.toml # Mops dependencies
├── src/
│ └── your_canister/
│ └── main.mo # Your canister code
├── .mops/ # Installed packages (auto-generated)
└── node_modules/ # Node dependencies

Dependencies

Hoosat-mo automatically installs these dependencies:

  • base - Motoko base library
  • blake2b - Blake2b-256 hashing for Schnorr sighashes
  • sha2 - SHA-256 hashing for ECDSA sighashes
  • json - JSON parsing for API responses
  • base64 - Base64 encoding utilities

These are managed automatically by Mops.

Configuration

Basic dfx.json Configuration

Minimal configuration for Hoosat-mo:

{
"canisters": {
"hoosat_wallet": {
"main": "src/hoosat_wallet/main.mo",
"type": "motoko"
}
},
"defaults": {
"build": {
"packtool": "mops sources"
}
},
"version": 1
}

Production Configuration

For production deployment with ECDSA:

{
"canisters": {
"hoosat_wallet": {
"main": "src/hoosat_wallet/main.mo",
"type": "motoko",
"declarations": {
"output": "src/declarations/hoosat_wallet",
"bindings": ["js", "ts", "did", "mo"]
}
}
},
"defaults": {
"build": {
"packtool": "mops sources"
},
"replica": {
"subnet_type": "system"
}
},
"networks": {
"local": {
"bind": "127.0.0.1:4943",
"type": "ephemeral"
},
"ic": {
"providers": [
"https://icp-api.io"
],
"type": "persistent"
}
},
"version": 1
}

ECDSA Key Configuration

Local Development (dfx_test_key)

For local testing, use the test key:

let wallet = Wallet.createMainnetWallet("dfx_test_key", ?"hoosat");

Production (IC Mainnet)

For production, use production keys:

let wallet = Wallet.createMainnetWallet("key_1", ?"hoosat");

Important: You need proper permissions for production keys. Contact DFINITY for access.

Verification

After installation, verify everything works:

Create a Test File

Create src/test/main.mo:

import Address "mo:hoosat-mo/address";
import Debug "mo:base/Debug";

actor {
public func test() : async Text {
// Test hex conversion
let hex = "0102030405";
let bytes = Address.arrayFromHex(hex);
let result = Address.hexFromArray(bytes);

Debug.print("Test passed!");
return result;
};
};

Deploy and Test

dfx deploy test
dfx canister call test test

Expected output:

("0102030405")

Troubleshooting

Common Issues

1. Mops Not Found

Error: mops: command not found

Solution:

npm install -g ic-mops
# or
npm i -g ic-mops

2. Package Not Found

Error: package hoosat-mo not found

Solution:

# Ensure mops.toml exists in project root
mops add hoosat-mo
mops install

3. DFX Deployment Fails

Error: Cannot find packtool

Solution: Add to dfx.json:

{
"defaults": {
"build": {
"packtool": "mops sources"
}
}
}

4. Import Errors

Error: import error: package "hoosat-mo" not defined

Solution:

# Reinstall dependencies
mops install
# Clean and rebuild
dfx build --clean

5. ECDSA Key Not Available

Error: ecdsa_public_key failed: key not available

Solution:

# For local development, ensure you're using dfx_test_key
# The key is only available on IC mainnet or local replica with proper setup

Next Steps

Now that you have Hoosat-mo installed, you can:

  1. Quick Start Guide - Build your first Hoosat canister
  2. Address Module - Learn address generation
  3. Wallet Module - Explore wallet functionality
  4. Examples - See working code samples

Additional Resources

Getting Help

If you encounter issues:

  1. Check the GitHub Issues
  2. Join our Discord
  3. Ask in Telegram
  4. Review the test directory for examples