Ethereum: How to batch multiple calls through a single function?

Bateching Change Kapuskusting The third selven function: intelligent approach contractor

Who builds intelligent contracts in the Ethereum block chain, developers from the challenge improves monolithic functions that are knit cards. In this art, we explore Holl for Banch through intelligent techniques mixed with one vaula.

The problem of monolithic functions

Monolith fires are configured to determine the shoulder manager. Separating Multipleve calls to lead to problems and the complexity of the Creator. For example:

Gas ​​consumption : For each call, there is a gas cost, which can rise rapidly more than several requests.

Increen Complerity : With the corresponding complex functions, the contract is drawn up for maintaining and Debig.

Solution: Batch call third is a single function

To deal with these, we set the batch measurements with one function. This approach allLows:

  • Baatch Multiple Calls : We create one function of several income and performed them.

2

Contract structure

The three out of three of our contacts are starting: “Batchcall”, the action of the action “and the Shockleeror”. Batchcall is a functional multiple income, while the implementation of the acts of the law. Sleell functional is used to handle errors with Y during the batch.

charity

We have a solid force ^0.8,8,0;

Agreement BatchCall {

// occurred to the corresponding value of addresses

word (address => intint256) public stakes;

/// a group of feed values

Outed256 [] public valves;

// Arry’s current index

OP256 Curre index = 0;

// / event imitates Secusy successes.

When speaking BatchCallexecuced (Addrexed User Indexed, Indexed Callfunction);

/// Function of the specified address to perform one function

functional leader (dressing) public {

Callfunction] = valves [Cirentidex];

Current Infrainex ++;

}

/// The Breple is invited to one performance

functional batch (dress] inputaddresses, inputadreress, int256 [] memory values) Public {

// Selective input groups lungs and their contents

require (inputes.length = == == Bearays.Length, “the length supply group does not match”);

require (value rays.length = = being. Length “,” Inarray lengths do not match “);

// installments all watches to complete the synchhy

for (UINT256 A = 0;

Income [ins [i] = value arreyarerays [i];

}

// Run a Batch Function at Each Input Address

(Dressing User Inputs) {

ExecuteFunction (USA);

}

}

// / event is low

When speaking BatchCallexecuted (Addrexed User Indexed User, Unputes);

// / error processing mechanism

Batchcallerror (string memory Mesage);

}

“ S

Imple use

Ethereum: How to batch multiple calls through a single function?

We find a simple exam Sing TW feed addresses and values.

charity

Batchcall (dress [] Memorial Inputadreress, Volents Unkut) Public {

// Run each batch function at a different address

(Dressing User Inputs) {

ExecuteFunction (USA);

}

// Treat Stoll error may have a blade item

Handleerror (“Batch Call Error”);

}

Batchcallerror (Saving a message) Public {

Imithed BatchCelexecececed (msg.

AUTOMATING COMPLIANCE ADVANTAGES

پاسخ دهید

آدرس ایمیل شما منتشر نخواهد شد. فیلدهای الزامی هستند.