Complete Example
Here’s a complete example from the TAPLE Core repository that demonstrates basic node usage:/home/daytona/workspace/source/examples/basic_usage/src/main.rs:1.
Key Concepts
Node Initialization
Generate a key pair
Every node requires a cryptographic key pair for identity:For production, use a secure seed or load existing keys.
Working with Keys
Generate additional keys for signing requests:KeyDerivator::Ed25519KeyDerivator::Secp256k1(requiressecp256k1feature)
Creating Requests
All write operations require creating and signing anEventRequest:
/home/daytona/workspace/source/core/src/node.rs:71 for the node build implementation.
Handling Notifications
The node communicates state changes through notifications. You must consume notifications to prevent blocking:Single Notification
Notification Handler
Drop Notifications
If you don’t need to process notifications:/home/daytona/workspace/source/core/src/node.rs:356 for notification handling methods.
API Operations
TheApi object provides methods for interacting with the node.
Reading Data
Get a Subject
Get Events
Get Subjects
/home/daytona/workspace/source/core/src/api/api.rs:32 for the complete API reference.
Approval Operations
With theapproval feature enabled, you can handle voting requests:
Preauthorized Subjects
Allow the node to accept events for specific subjects:Error Handling
All API operations returnResult<T, ApiError>. Common error types:
ApiError::NotFound- Requested resource doesn’t existApiError::InvalidParameters- Invalid identifier or parametersApiError::InternalError- Internal node error
Best Practices
- Always handle notifications - Unprocessed notifications will block the node
- Use proper database -
MemoryManageris only for testing; use persistent storage in production - Secure key management - Never hardcode secret keys; use secure key storage
- Graceful shutdown - Always call
shutdown_gracefully()to properly close the node - Enable required features - Only enable features you need to minimize dependencies
Running the Example
To run the basic usage example from the repository:Next Steps
- Explore the API Reference for detailed API documentation
- Check out TAPLE Client for a complete client implementation
- Visit www.taple.es for comprehensive guides and tutorials
