Ethereum: How datatypes work in solidity?

How data types work in solidity: a guide

Ethereum: How datatypes work in solidity?

While we immerse ourselves in the world of smart contracts on Ethereum blockchain, one of the most fundamental concepts to enter is the types of data used in the solidity programming language. In this article, we will explore how data types work in solidity and provide a detailed explanation of their use.

EVM data types

The EVM (Ethereum Virtual Machine) uses a 32 bytes key values ​​store to store data. This store is accessible by contracts using the “Contract Address” syntax. However, this store is not directly accessible from outside the contract. To interact with external data, Solidey uses its own data types.

whole (uint)

In Solidity, integers are stored as 32 -bit (uint") integers. These integers may contain values ​​ranging from 0 to 2 ^ 32 - 1. For example:

Solidity

Pragma Solidity ^ 0.8,0;

simple contract {

uint public public;

public unit () public {

++ counter;

}

}

'

When we call the "Intestructive" function, the contract increments a local variable and updates its storage value.

Channels (chain)

The solidity chain data type is used to store character strings. The chains are defined using the keyword "String":

Solidity

Pragma Solidity ^ 0.8,0;

Contract mycontract {

Chain public message;

Setmessage function (chain memory _message) public {

message = _Message;

}

}

'

When we call the "Setmessage" function, it updates a local variable and stores the storage entry chain.

bytes (bytes)

In Solidity, bytes are used to store binary data. The bytes can contain values ​​ranging from 0 to 255 for each of its four elements. For example:

Solidity

Pragma Solidity ^ 0.8,0;

Contract mycontract {

Bytes public image;

Setimage function (bytes Memory _Image) Public {

image = _image;

}

}

'

When we call the "Setimage" function, it updates a local variable and stores the table of storage input bytes.

Address (address)

In Solidity, addresses are used to represent the own address of the contract. Addresses are represented as hexadecimal strings of 40 bytes:

Solidity

Pragma Solidity ^ 0.8,0;

Contract mycontract {

approach the public owner;

}

` ‘

The “owner” variable is initialized with a random address.

Comparison of data types

| Data type | Use |

| — | — |

| Uint | Integer (32 bits) |

| String | String |

| bytes | Binary data (4 -elements table) |

| Address | Contract address |

Conclusion

In conclusion, Solidity provides several integrated types of data that allow developers to store and manipulate different types of data within their contracts. It is essential to understand the use of these types of data to build effective and scalable intelligent contracts.

By mastering how to use data types in Solidey, you can write more efficient and robust intelligent contracts that interact with external data in a secure and controlled manner.

ETHEREUM THERE REQUIRE PROCESS

Leave a Comment

Your email address will not be published. Required fields are marked *