StarkNet Address Checker
A Rust library for validating and checking StarkNet addresses. This crate provides utilities to verify if and address is a Smart Wallet or a user deployed Smart Contract, it can also check if an address is a valid StarkNet address and pad incomplete starknet addresses that are one bit shorter.
Features
-
Validate StarkNet Addresses: Check if an address is a valid StarkNet address.
-
Pad Incomplete Addresses: Automatically pad addresses with zeros to match the required length.
-
Check Smart Contracts: Verify if an address belongs to a smart contract on StarkNet.
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0" # Replace with the latest version check crates.io for latest version
= "0.3.0" # Required for StarkNet provider functionality
Usage
Validating a StarkNet Address
The is_valid_starknet_address function checks if an address is a valid StarkNet address. If the address is valid, it returns the address as-is. If the address is incomplete but valid, it pads it with zeros to match the required length. If the address is invalid, it returns false.
use is_valid_starknet_address;
Checking if an Address is a Smart Contract
The check_address function verifies if a given address belongs to a smart contract on StarkNet. It requires an RPC URL to interact with the StarkNet network.
use ;
async
API Reference
is_valid_starknet_address(address: &str) -> (bool, String)
-
Input: A StarkNet address as a string.
-
Output: A tuple containing:
∘ A boolean indicating if the address is valid.
∘ The validated address (padded if necessary) or the original address if already valid.
check_address(address: &str, options: &CheckRpcUrl) -> Result<CheckAddressResult>
-
Input:
∘ A StarkNet address as a string.
∘ A
CheckRpcUrlstruct containing the RPC URL for the StarkNet network. -
Output: A
Resultcontaining:∘
CheckAddressResultwith a boolean fieldis_smart_contractindicating if the address is a smart contract.
An error if the request fails.
License
This project is licensed under the MIT License. See the LICENSE file for details.