Blog

How to use inline assemby to manipulate storage variables

In the following code-snippet, we have two variables that reflect the deposits from Charles and Bob:

a) charlesDeposits

b) bobDeposits

The increaseDeposits function uses assembly to fetch, increase and re-store deposits for Charles.

In the first step, a pointer to slot0 is created, which reflects Charles' deposit amount.

In the second step, the corresponding value is cached inside the function and in the third step it is increased by the input parameter.

Finally, the adjusted value is then stored again in the corresponding slot.