Snap Coin Core
A rust crate for developing with and for Snap Coin
Some General Tips
- Default binary to string serialization is
base36(letters + numbers only). - Most helper functions (like
build_block(...),build_transaction(...)) take a blockchain data provider (this is a trait!), which is a struct that can access basic blockchain data and perform certain fetches etc. These are most commonlycore::Node.blockchainandapi::Client.
Getting started
Installation
To utilize this library in your project run
Utilization
There are two main ways of connecting and interacting with a snap coin network
As a standalone node (DIFFICULT)
Your program becomes the node, and you have direct access over its blockchain, peers, connected nodes, status. This is best for when you need fast, direct access. This is not recommended if you are creating a program that a user might want to run along side a existing node or if the user would like to create more than one instance of this program. This is the fastest approach as you directly interface with the node, without any translation layer in between.
- Create a new node instance (WARNING: Only one instance can exist in a program at once otherwise a panic will happen!)
Notice howlet node: = new; // Path where the node will be stored, port to host nodenew()returns aArc<RwLock<Node>>instead of just a node. This is due to the fact that the node is passed around the internal code a lot and this abstractions makes it async safe. - Call and access functions of the node
Notice how we clone the node, and call a static function on thesubmit_block.await?; println!;Nodestruct. WARNING: When accessing direct values from theNodestruct, make sure to callnode.read().awaitornode.write().awaitif the internal state of the node will be modified by this operation. - Full example:
use ; use Arc; use RwLock; async
As a Snap Coin API interface with an existing node (EASY)
This approach makes your program a API client to a node that is already hosted (like snap-coin-node) by your user. This approach is slower and does not have full direct access to the node, however, it is a lot more lightweight then the approach mentioned before. This should be used when there will be more then one instance of this program running, for example a wallet can just connect to a hosted node (by the user) instead of being its own node. It is important to understand that the node this client will be connecting too must be 100% trusted as it can modify, spoof, and fake all interactions with this program.
- Connect to a already running (in a separate program) node, that has a Snap Coin API server exposed
let client = connect.await?; - Call functions on the client to obtain and change blockchain / node state
println!; - Full Example:
use ; async
Documentation and Development Reference
Available here: rust.rs
Support this Project
You can support this project in many ways, but it is best to just develop and use Snap Coin. I take pride in this project, and by extent in this code. You can help us grow, as Snap Coin is a community effort, by creating apps that utilize Snap Coin, trading, using it as a medium of exchange for things like jobs.
Help Develop Snap Coin
This repo is always available for pull requests, i highly incentivize reading the code, documentation, and making new features. If you need any help, reach out to me on discord @ice.is.this or via email ice.is.this@gmail.com. Any issues can be reported in the issues tab.
Join the discord
Join and grow the community: discord.gg
Donate
You can buy the developer a coffee and help me keep my motivation:
Snap Coin: 60bamx9k23wcbv6m4xo26h4lsgxwlb83wv2nf1n0hnnatkj9vx
Bitcoin: bc1qacw3l33kzdg96tu268az3chsyrg3pcup0dat9j
Etherum: 0xef98b5ea67248e8a3ee4f4d3674c8ebb2be4e39a
Solana: 8ST3miN2KLdTNXa7pkK1g2qFB3xKzpe1bvCC2QuVBDHG
BNB Smart Chain 0xef98b5ea67248e8a3ee4f4d3674c8ebb2be4e39a