• 8
  • 0

Ethereum: Correct use of a function called (or delegatecall) in firmness

The call 'is the' is the delegatecall 'calling' two of the most commonly used functions in firmness, programming language to create decentralized applications on Blockchain Ethereum. In this article, we will explore how to properly use these functions, including the best practices and examples.

What is the call and delegatecall?

  • FunctionCall ‘allows you to send value from one contract to another without transferring and values ​​from the local archive.

  • The function `delegatecall is a variation of ‘call’ function that sends the value directly in the internal state of the contract.

In this article, we will focus on using both functions in the strength contract, including scenarios and calls and calls for other contracts.

Use of call function

Function Call 'can be used as follows:

* Sending value : It is possible to send a value from one contract to another by using acall function ‘.

* CONSTRUCTION

Ethereum: How to properly use the call (or delegatecall) in solidity

: Function Calls' is also suitable for changing the condition, such as updating the variable or value setting.

Example: The correct use of call function

Strength

Pragma Solidity ^0.8.0;

SimpleContratct {Agreement

mapping (address => nint) public value;

// works to change the internal status of the contract

Updatestate (nint _value) public function {

values ​​[msg.sender] = _value;

Iche

// works to call another contract and send values ​​from this contract

Function test (nint quantity) public {

Address (0xf5ea38b6b9644224DA1AECBC1219E8543C0689b2) .call (abocodewithsignatures ("deposit (nint)", amount));

Iche

Iche

In the example above, we defineSimpleconttract ‘with two functions:Updatestate is a test. The function is used to call for another contract (`0xf5e38b6b96442224DA1AECBC1219E8543C0689b2) usingcall.

Use of delegatecall

function

The delegatecall 'function can be used as follows:

* CONSTRUCTION : The function ofdelegatecallis also suitable for changing the condition, such as updating the variable or value setting.

* Sending value : It is possible to send a value from one contract to another usingdelegatecall.

Example: The correct use of delegatecall function

Strength

Pragma Solidity ^0.8.0;

SimpleContratct {Agreement

mapping (address => nint) public value;

// works to change the internal status of the contract

Updatestate (nint _value) public function {

values ​​[msg.sender] = _value;

Iche

// delegated call function only for tests

Function a test () pure pure overpass {

Address (0xf5e38B6B9644224DA1AECBC1219E8543C0689b2) .Delegatecall (inhamentation

Iche

Iche

In the example above, we defineSimpleconttract ‘with two functions:Updatestate is a test. The function is used to call another contract (`0xf5e38B6B9644224DA1AECBC1219E8543C0689b2) using the function Delegatecall ‘.

Best Practice

When using both functions, keep in mind:

  • Always check the documentation of a function to any restrictions or restrictions when used.

  • Be sure to use the address of the correct contract and signature for a function called.

  • Keep in mind that the function of Calis may not support all types of values ​​(eg string, structures).

  • State amendment must be made to ensure conflicts with other contracts.

Following these guidelines and examples, it is possible to effectively use both functionscall ‘is delegatecall’ in the strength contract. Happy code!

ethereum convert public verify

Add Comment

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