> For the complete documentation index, see [llms.txt](https://stylus-1.gitbook.io/stylusguide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stylus-1.gitbook.io/stylusguide/4.-understanding-smart-contract-storage-simple-storage/writing-the-simple-storage-contract.md).

# Writing the Simple Storage Contract

In this section, we will write a simple storage contract to demonstrate how to read from and write to storage in Arbitrum Stylus.

**Create a New Project**

Use the `cargo-stylus` command to create a new project:

```sh
cargo stylus new simple_storage
cd simple_storage
```

**Edit the Contract Code**

Open the `src/lib.rs` file and replace the content with the following code:

```rust
// Allow `cargo stylus export-abi` to generate a main function.
#![cfg_attr(not(feature = "export-abi"), no_main)]
extern crate alloc;

/// Use an efficient WASM allocator.
#[global_allocator]
static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT;

/// Import items from the SDK. The prelude contains common traits and macros.
use stylus_sdk::{alloy_primitives::U256, prelude::*};

// Define some persistent storage using the Solidity ABI.
// `Storage` will be the entrypoint.
sol_storage! {
    #[entrypoint]
    pub struct Storage {
        uint256 value;
    }
}

/// Declare that `Storage` is a contract with the following external methods.
#[external]
impl Storage {
    /// Gets the value from storage.
    pub fn get_value(&self) -> U256 {
        self.value.get()
    }

    /// Sets a value in storage to a user-specified value.
    pub fn set_value(&mut self, new_value: U256) {
        self.value.set(new_value);
    }

    /// Multiplies the stored value by a user-specified value.
    pub fn mul_value(&mut self, multiplier: U256) {
        self.value.set(multiplier * self.value.get());
    }

    /// Adds a user-specified value to the stored value.
    pub fn add_value(&mut self, increment: U256) {
        self.value.set(increment + self.value.get());
    }

    /// Increments `value` and updates its value in storage.
    pub fn increment(&mut self) {
        let value = self.value.get();
        self.set_value(value + U256::from(1));
    }
}
```

#### Explanation:

1. **Allocator:**
   * Using `mini_alloc` for an efficient WASM allocator.
2. **Imports:**
   * Importing necessary items from the Stylus SDK, including `U256` from `alloy_primitives` and common traits and macros from the `prelude`.
3. **Storage Definition:**
   * Using the `sol_storage!` macro to define the `Storage` struct with a single `uint256` field.
4. **External Methods:**
   * `get_value`: Returns the current value from storage.
   * `set_value`: Sets the storage value to a new user-specified value.
   * `mul_value`: Multiplies the current storage value by a user-specified value.
   * `add_value`: Adds a user-specified value to the current storage value.
   * `increment`: Increments the current storage value by 1.

#### Deploying and Testing the Contract

1. **Check the Contract:**

   ```sh
   cargo stylus check --endpoint https://sepolia-rollup.arbitrum.io/rpc
   ```
2. **Deploy the Contract:**

   Ensure you have a valid private key saved in a file (e.g., `private_key.txt`). The file should contain only the private key without any extra characters or spaces.

   ```sh
   cargo stylus deploy --private-key-path=/path/to/private_key.txt --endpoint https://sepolia-rollup.arbitrum.io/rpc
   ```
