# Core concepts · Chromia for EVM developers · Learn Chromia

> Before working through practical examples, it helps to see how core Solidity concepts map to Rell. The topics below cover the foundations of blockchain…

Source: https://chromia.com/learn/chromia-for-evm-developers/concepts/

Chromia for EVM developersLesson 5 of 8

1. [01Chromia for EVM developers](https://chromia.com/learn/chromia-for-evm-developers/introduction/)
2. [02Explore assets and transfers](https://chromia.com/learn/chromia-for-evm-developers/asset-transfer/)
3. [03Chromia dapp overview](https://chromia.com/learn/chromia-for-evm-developers/chromia-stack/)
4. [04Authentication](https://chromia.com/learn/chromia-for-evm-developers/compare-authentication/)
5. [05Core concepts](https://chromia.com/learn/chromia-for-evm-developers/concepts/)
6. [06Create a news feed dapp](https://chromia.com/learn/chromia-for-evm-developers/news-feed/)
7. [07Extend news feed dapp](https://chromia.com/learn/chromia-for-evm-developers/news-feed-follower/)
8. [08Summary](https://chromia.com/learn/chromia-for-evm-developers/summary/)

[Learn](https://chromia.com/learn/)[Chromia for EVM developers](https://chromia.com/learn/chromia-for-evm-developers/)

05 / 08

# Core concepts

Before working through practical examples, it helps to see how core Solidity concepts map to Rell. The topics below cover the foundations of blockchain development:

* Setting up smart contracts and dapps
* Declaring state variables and models
* Interacting with a dapp or smart contract
* Writing internal functions
* Querying data

## Smart contract and dapp states

First, you define a Solidity contract with a struct and a state variable, then build the equivalent in Rell.

**Solidity:**

Solidity

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract CompanyManager {
     // Define struct for our data
     struct Company {
        string name;
        string full_address;
    }

    // Declare a state variable holding our companies in an array
    Company[] public companies;
}
```

**Rell:**

Rell

```
module;

entity company {
    name: text;
    address: text;
}
```

The two versions look much alike. The difference is that Rell needs no variable to hold the companies: once you define an entity, it becomes part of your dapp's state when you deploy.

In Solidity, storing an array of data in a contract can be a concern because of gas fees. Rell removes that concern. Each entity instance is stored on-chain in a relational database, and storing it costs no gas. Chromia handles resources and fees differently: like a traditional cloud provider, it lets developers lease containers with a fixed allocation of vCPU, RAM, storage, and I/O. The lease covers the costs, so users pay no transaction (gas) fees, and you can design user experiences that feel like conventional Web2 applications.

Under the hood, your dapp's state gets a table called `company` with the attributes `name` and
`address`. This works much like a code-first ORM generating a database table. See the [entity documentation](https://docs.chromia.com/rell/language-features/modules/entity) for details.

## Interacting with a dapp or smart contract

To interact with a Solidity smart contract, you call its public functions, which act as entry points for running the contract's logic. Here is one added to the example contract:

Solidity

```
function addCompany(string memory _name, string memory _address) public {
        Company memory newCompany = Company(_name, _address);
        companies.push(newCompany);
}
```

Rell uses operations for this purpose; they play the role of Solidity's public functions. You run an operation by signing and sending a transaction that contains the operation name and its parameters. The Chromia platform then executes the operation body, which may change your dapp's state. The following operation adds a new company to the state:

Rell

```
operation create_company(name: text, address: text) {
    create company( name, address );
}
```

The `create` keyword inside the operation inserts a new record into the company entity. In Solidity terms, this is like instantiating a Company and pushing it onto the companies array. Because Chromia has no gas fees, you can change state directly without having to manage gas costs, which keeps development on Chromia inexpensive and simple. The [operation documentation](https://docs.chromia.com/rell/language-features/modules/operation) covers operations in full.

## Internal functions

To restrict a Solidity function to calls from inside the contract, you mark it `private`. The following private function performs a basic check on the company name:

Solidity

```
function isValidName(string memory _name) private returns (bool) {
        return bytes(_name).length > 0; // Simple check: name is not empty
}
```

Rell functions serve the same purpose: they hold reusable logic such as validation or data lookups. They are callable only from within your dapp, whether from operations, queries, or other functions. When an operation calls a function, that function can also modify your dapp's state, which helps you keep code well organized and reusable.

Rell

```
function is_valid_name(name: text) {
    not name.empty();
}
```

Here is the complete example so far in both Rell and Solidity:

Rell

```
module;

entity company {
    name: text;
    address: text;
}

operation create_company(name: text, address: text) {
    require(is_valid_name(name), "Invalid name");
    create company( name, address );
}

function is_valid_name(name: text) {
    not name.empty();
}
```

Solidity

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract CompanyManager {
    struct Company {
        string name;
        string address;
    }

    Company[] private companies;

    function addCompany(string memory _name, string memory _address) public {
        require(isValidName(_name), "Invalid company name");
        Company memory newCompany = Company(_name, _address);
        companies.push(newCompany);
    }

    function isValidName(string memory _name) private pure returns (bool) {
        return bytes(_name).length > 0; // Simple check: name is not empty
    }
}
```

Both versions call the validation function to confirm the name is valid, and both check the result with the `require` function. When validation fails, an error is thrown and the transaction, including its state changes, is rolled back. The [function documentation](https://docs.chromia.com/rell/language-features/modules/function) has more detail.

## Querying data

Reading state from a Solidity contract usually means calling public getter functions. Solidity generates getters for public state variables automatically, and you can write your own public functions to return more complex or computed data. Functions that leave the contract's state untouched can be marked as view, so calling them externally consumes no gas. The example below returns a company struct given its index:

Soldity

```
function getCompany(uint _index) public view returns (Company memory) {
    return companies[_index]; // Returns the Company struct at the given index
}
```

Rell retrieves data with queries, which correspond to Solidity's public view functions. A query can read data but cannot change the database state. Paired with Rell's built-in query language, queries are a powerful tool.

Rell

```
query get_company(id: rowid) {
    return company @ { .rowid == id };
}
```

Here, Rell's query language looks up the company by its `row_id` identifier. The approach is simple and efficient while still supporting powerful data retrieval. The [query documentation](https://docs.chromia.com/rell/language-features/modules/query) explains queries in more depth.

## Summary

You have now seen the basic concepts involved in moving from Solidity to Chromia and Rell. The sections that follow walk through examples of different concepts to help you, as a Solidity developer, get productive on Chromia.

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Authentication**](https://chromia.com/learn/chromia-for-evm-developers/compare-authentication/)[Next →**Create a news feed dapp**](https://chromia.com/learn/chromia-for-evm-developers/news-feed/)

On this page

* [Smart contract and dapp states](#smart-contract-and-dapp-states)
* [Interacting with a dapp or smart contract](#interacting-with-a-dapp-or-smart-contract)
* [Internal functions](#internal-functions)
* [Querying data](#querying-data)
* [Summary](#summary)
