This smart contract, written in Rust using the NEAR Protocol framework, provides functionality for managing a registry of universities. It enables adding, retrieving, and organizing universities by their account IDs and names.
- Add University: Allows the contract owner to register universities with a name and unique account ID.
- Retrieve by Account ID: Fetch a university's details using its account ID.
- Retrieve by Name: Get a list of universities that share the same name.
- Retrieve All Universities: Retrieve a list of all registered universities.
- Rust installed on your system. Follow the instructions here.
- NEAR CLI installed. Follow the instructions here.
- NEAR testnet or mainnet account for deploying the contract.
-
Data Structures
-
University
: Represents a university with two fields:name
: The name of the university.account_id
: A unique account ID associated with the university.
-
StorageKey
: Enum to manage keys used for persistent storage.
-
-
Contract Implementation
UniversityRegistry
: Contains two main maps:universities_accounts
: Maps account IDs toUniversity
objects.universities_by_name
: Maps university names to a list ofUniversity
objects.
-
add_university(name: String, account_id: String) -> University
- Adds a new university to the registry.
- Accessible only by the contract owner.
- Panics if the account ID already exists.
-
get_all_universities() -> Vec<(String, University)>
- Returns a list of all universities in the registry.
-
get_universities_by_name(name: String) -> Vec<University>
- Retrieves universities that match the given name.
-
get_university_by_account_id(account_id: String) -> Option<University>
- Fetches a university by its account ID.
add_university_by_name(university: University)
- Helper method to organize universities by name.
Install cargo-near
and run:
cargo near build
cargo test
Deployment is automated with GitHub Actions CI/CD pipeline.
To deploy manually, install cargo-near
and run:
cargo near deploy <account-id>
- cargo-near - NEAR smart contract development toolkit for Rust
- near CLI - Interact with NEAR blockchain from command line
- NEAR Rust SDK Documentation
- NEAR Documentation
- NEAR StackOverflow
- NEAR Discord
- NEAR Telegram Developers Community Group
- NEAR DevHub: Telegram, Twitter