Skip to content

Unity UPM package for Casper Network SDK - blockchain integration

Notifications You must be signed in to change notification settings

SamDreamsMaker/com.caspernetwork.sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Casper Network Unity SDK

A comprehensive Unity SDK for integrating Casper Network blockchain functionality into Unity games and applications.

πŸš€ Features

  • Clean Architecture: Built with SOLID principles and proven design patterns
  • Easy Integration: Simple, Unity-friendly API
  • Async/Await Support: Full async support with Unity main thread dispatching
  • Account Management: Key generation, import, and balance queries
  • Transaction System: Fluent transaction builder with validation
  • Network Flexibility: Support for Mainnet, Testnet, and custom networks
  • Error Handling: Comprehensive exception hierarchy
  • Type Safe: Strongly typed models and interfaces

πŸ“‹ Requirements

  • Unity 2022.3 LTS or higher
  • .NET Standard 2.1 or higher
  • Windows, macOS, Linux, WebGL, iOS, Android support

🎯 Quick Start

1. Installation

  1. Clone or download this repository
  2. Copy the Assets/CasperSDK folder to your Unity project's Assets folder
  3. Import the required DLLs (Casper.Network.SDK) into Assets/CasperSDK/Plugins/

2. Configuration

Create a network configuration:

  1. Right-click in Project window
  2. Create > CasperSDK > Network Configuration
  3. Configure your network settings (Mainnet/Testnet/Custom)

3. Initialize the SDK

using CasperSDK.Core;
using CasperSDK.Core.Configuration;

public class MyGame : MonoBehaviour
{
    [SerializeField] private NetworkConfig networkConfig;

    private void Start()
    {
        // Initialize the SDK
        CasperSDKManager.Instance.Initialize(networkConfig);
    }
}

4. Use the SDK

// Generate a new key pair
var accountService = CasperSDKManager.Instance.AccountService;
var keyPair = await accountService.GenerateKeyPairAsync();

// Get account balance
var balance = await accountService.GetBalanceAsync(publicKey);

// Build and submit a transaction
var transactionService = CasperSDKManager.Instance.TransactionService;
var transaction = transactionService.CreateTransactionBuilder()
    .SetFrom(senderPublicKey)
    .SetTarget(recipientPublicKey)
    .SetAmount("2500000000") // 2.5 CSPR in motes
    .Build();

var txHash = await transactionService.SubmitTransactionAsync(transaction);

πŸ—οΈ Architecture

The SDK follows clean architecture principles with the following design patterns:

Design Patterns Used

  • Singleton Pattern: CasperSDKManager - Single entry point for the SDK
  • Factory Pattern: NetworkClientFactory - Creates appropriate network clients
  • Builder Pattern: TransactionBuilder - Fluent API for transaction construction
  • Repository Pattern: AccountService - Abstraction for account data access
  • Strategy Pattern: Different network implementations (Mainnet/Testnet)
  • Observer Pattern: Event system for blockchain events

Project Structure

CasperSDK/
β”œβ”€β”€ Runtime/
β”‚   β”œβ”€β”€ Core/
β”‚   β”‚   β”œβ”€β”€ Configuration/       # Network and SDK settings
β”‚   β”‚   β”œβ”€β”€ Interfaces/          # Service interfaces
β”‚   β”‚   β”œβ”€β”€ CasperSDKManager.cs  # Main SDK entry point
β”‚   β”‚   └── Exceptions.cs        # Custom exceptions
β”‚   β”œβ”€β”€ Network/
β”‚   β”‚   β”œβ”€β”€ RPC/                 # JSON-RPC client
β”‚   β”‚   └── Clients/             # Network client implementations
β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”œβ”€β”€ Account/             # Account management
β”‚   β”‚   └── Transaction/         # Transaction services
β”‚   β”œβ”€β”€ Models/                  # Data models
β”‚   β”œβ”€β”€ Unity/                   # Unity-specific integrations
β”‚   └── Examples/                # Example scripts
β”œβ”€β”€ Editor/                      # Editor tools and utilities
└── Tests/                       # Unit and integration tests

πŸ“š API Documentation

CasperSDKManager

Main entry point for the SDK. Implements Singleton pattern.

// Initialize
CasperSDKManager.Instance.Initialize(config);

// Access services
var accountService = CasperSDKManager.Instance.AccountService;
var transactionService = CasperSDKManager.Instance.TransactionService;

// Shutdown
CasperSDKManager.Instance.Shutdown();

IAccountService

Manages Casper accounts and keys.

Task<Account> GetAccountAsync(string publicKey);
Task<string> GetBalanceAsync(string publicKey);
Task<KeyPair> GenerateKeyPairAsync(KeyAlgorithm algorithm);
Task<KeyPair> ImportAccountAsync(string privateKeyHex, KeyAlgorithm algorithm);

ITransactionService

Handles transaction creation and submission.

ITransactionBuilder CreateTransactionBuilder();
Task<string> SubmitTransactionAsync(Transaction transaction);
Task<ExecutionResult> GetTransactionStatusAsync(string transactionHash);
Task<long> EstimateGasAsync(Transaction transaction);

TransactionBuilder

Fluent API for building transactions.

var transaction = service.CreateTransactionBuilder()
    .SetFrom(sender)
    .SetTarget(recipient)
    .SetAmount("1000000000")
    .SetGasPrice(1)
    .SetTTL(3600000)
    .Build();

πŸŽ“ Examples

See Assets/CasperSDK/Runtime/Examples/BasicSDKExample.cs for a comprehensive example.

πŸ§ͺ Testing

The SDK includes comprehensive unit and integration tests.

Running Tests

  1. Open Unity Test Runner (Window > General > Test Runner)
  2. Select "Runtime Tests" or "Editor Tests"
  3. Click "Run All" or run individual tests

Test Categories

  • Unit Tests: Test individual components with mocked dependencies
  • Integration Tests: Test against Casper Testnet (requires internet)

πŸ” Security

⚠️ IMPORTANT: Never commit private keys to version control!

  • Use Unity's secure storage for private keys in production
  • Test with Testnet before deploying to Mainnet
  • Always validate user inputs
  • Keep dependencies up to date

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the source repository (not this package repo): πŸ‘‰ https://github.com/SamDreamsMaker/Casper-Network-Unity-SDK
  2. Create a feature branch
  3. Follow the existing code style and patterns
  4. Add tests for new functionality
  5. Submit a pull request to the source repository

⚠️ Note: Do NOT submit PRs to com.caspernetwork.sdk - it's auto-generated from the source repo.

πŸ“„ Code Quality Standards

This SDK follows strict code quality standards:

  • βœ… SOLID principles
  • βœ… Clean code practices
  • βœ… Comprehensive error handling
  • βœ… XML documentation for all public APIs
  • βœ… Unit tests for all components
  • βœ… Consistent naming conventions

πŸ“ License

MIT License - see LICENSE

πŸ”— Links

πŸ“§ Support

For issues, questions, or contributions:

πŸ—ΊοΈ Roadmap

  • Core infrastructure
  • Network layer with JSON-RPC
  • Account management
  • Transaction builder
  • Transaction signing (ED25519 & SECP256K1)
  • CSPR transfers
  • Key import/export (PEM format)
  • Smart contract deployment
  • Smart contract interaction
  • Event listening (SSE - in progress)
  • WebGL support optimization
  • Sample projects (Wallet βœ…, NFT, Token)

Version: 1.0.0
Last Updated: December 2025
Status: Production Ready


Source Repository: https://github.com/SamDreamsMaker/Casper-Network-Unity-SDK

About

Unity UPM package for Casper Network SDK - blockchain integration

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages