Buy Space

Buying space using the Rust SDK is simple. Bring the StorageHandler trait into scope and call the buy_space function with an integer value. The parameter represents the amount of space to buy in GB.

Please note that buying space is a one-time process; consecutive purchases using the same account will result in a transaction failure. After purchase, the space can only be expanded or renewed.

```rust
use cess_rust_sdk::chain::ChainSdk;

use cess_rust_sdk::chain::storage_handler::StorageHandler;

// The account mnemonic that will be used to sign transactions.
const MNEMONIC: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice";

#[tokio::main]
async fn main() {
    let sdk = ChainSdk::new(MNEMONIC, "service_name");
    
    let result = sdk.buy_space(1).await;
    match result {
        Ok(r) => {
            println!("Storage Purchase successful: {:?}", r);
        }
        Err(e) => {
            println!("Storage Purchase failed: {:?}", e);
        }
    }
}
```

Last updated