Ethereum: Ethersjs: check that a transaction method in contract emitted an event

Ethereum: Ethers.js – Managing Transaction Methods Increments

introduction

In this article, we will examine how important it is to ensure that the transaction method in the intelligent agreement gives the event. In particular, we focus on the “GetTwowraddress” feature, which gives the “owner owner” event.

“getwowraddress” function

“GetTwowraddress” is called when the owner’s address changes in the contract:

The firmness `

GETOWNADDRESS () PUBLIC VIEW RETURNS (Address) Function {

Emple one refurbished (“owner”);

}

`

In this example, we give the event "owner owner with a specific message (" owner "). This means that every time the" GetTwowraddress "function is called, it sends this event to all Blockchain contracts and nodes.

Event problem certification

In order to ensure that the function of thegettownraddress’ applies to the right events, we can use eetters.js. Here’s an updated version of an agreement with some additional checks:

The firmness `

Pragman solidity ^0.8.0;

Import “

Import “

MyContratct {Agreement

Guides the private owner;

UINT256 Public Libra = 0;

Evenation Entry (String Memory MSG) properties;

GETOWNADDRESS () PUBLIC VIEW RETURNS (Address) Function {

Request (msg.sender == owner, “Only the owner of the contract can call this function”);

Emple one refurbished (“owner”);

Return address (0); // returns NULL to indicate that no new owner has been set

}

Setowner function (address _newower) public {

Request (_newower! = Budget owner, “cannot change owner or brand transfer”);

owner = _newower;

Emple one refurbished (“owner”);

balance = 0;

}

}

``

Explanation

In this updated agreement:

  • We added the training “requirement to check if the caller is the owner of the contract.

  • When you set the owner, we update the “owner of the variable and send the owner’s event with a message (” owner “).

3

conclusion

Check that events are essential transaction methods to ensure the safety and integrity of the contract. ETERS.JS allows you to detect all problems before implementing contracts in production. This example shows how to write stronger intelligent contracts by checking the emissions of events and the management of event emissions.

Bitcoin Called Need Spend Utxo