Expand description
§Neo Protocol
Core protocol types and interfaces for the Neo N3 blockchain.
§Overview
The neo_protocol module provides the core types and interfaces for interacting with the Neo N3 blockchain protocol. It includes:
- Account management and address handling
- NEP-2 password-protected key format support
- Protocol error definitions and handling
- Response types for Neo N3 RPC calls
- Role-based access control definitions
This module forms the foundation for blockchain interactions, defining the data structures and interfaces that represent the Neo N3 protocol.
§Examples
§Working with Neo N3 accounts
ⓘ
use neo3::neo_protocol::{Account, AccountTrait};
// Create a new account
let account = Account::create().unwrap();
println!("Address: {}", account.address());
println!("Script Hash: {}", account.script_hash());
// Create an account from a WIF (Wallet Import Format) string
let wif = "KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7";
let account = Account::from_wif(wif).unwrap();
// Sign a message
let message = b"Hello, Neo!";
let signature = account.sign(message).unwrap();
// Verify the signature
let is_valid = account.verify(message, &signature).unwrap();
assert!(is_valid);
§Using NEP-2 password-protected keys
ⓘ
use neo3::neo_crypto::PrivateKey;
use neo3::neo_protocol::nep2::{encrypt_to_nep2, decrypt_from_nep2};
// Encrypt a private key with a password (NEP-2 format)
let private_key = PrivateKey::from_slice(&[/* 32 bytes */]).unwrap();
let password = "your_secure_password_here";
let nep2_string = encrypt_to_nep2(&private_key, password).unwrap();
// Decrypt a NEP-2 string back to a private key
let nep2_string = "6PYVPVe1fQznphjbUxXP9KZJqPMVnVwCx5s5pr5axRJ8uHkMtZg97eT5kL";
let password = "your_secure_password_here";
let private_key = decrypt_from_nep2(nep2_string, password).unwrap();
Structs§
- Account
- Account
State - Address
Entry - Application
Log - Balance
- Claim
- Claimables
- Conflicts
Attribute - Diagnostics
- Execution
- Express
Contract State - Express
Shutdown - Hard
Forks - High
Priority Attribute - Invoked
Contract - LogNotification
- MemPool
Details - NEP2
- NEP2 provides methods for encrypting and decrypting NEO private keys according to the NEP2 standard specification.
- NeoAddress
- NeoBlock
- NeoNetwork
Fee - NeoProtocol
- NeoTransaction
Signer - NeoVersion
- NeoWitness
- Nep11
Balance - Nep11
Balances - Nep11
Token - Nep11
Transfer - Nep11
Transfers - Nep17
Balance - Nep17
Balances - Nep17
Transfer - Nep17
Transfers - NotValid
Before Attribute - Oracle
Request - Oracle
Response - Oracle
Response Attribute - Peers
- Plugin
- Populated
Blocks - RTransaction
- RTransaction
Signer - RawTransaction
- State
Height - State
Result - State
Root - States
- Storage
Change - Submit
Block - Transaction
Result - Unclaimed
Gas - Unspent
Transaction - Unspents
- Validate
Address - Validator
Enums§
Traits§
Functions§
- get_
nep2_ from_ private_ key - Compatibility functions to maintain backward compatibility with existing code These functions are provided for convenience and compatibility with the old API Encrypts a private key in hexadecimal format using NEP2.
- get_
private_ key_ from_ nep2 - Decrypts a NEP2-formatted string to retrieve the original private key.