[Very important] [solidity of the Indexed property when web3 or ethers class event filtering, solidity event definitions must add properties]

web3 call common types of errors: can not filter non-indexed parameters; must be null [The reason is that the field is defined as the amount is not indexed]

 

Reference section describes indexed: https://www.jianshu.com/p/131c07c6f72f

Official document describes:  https://solidity-cn.readthedocs.io/zh/develop/contracts.html?highlight=indexed

solidity language-defined events can increase [in the event parameter indexedattributes, such attributes can be increased up to three parameters. Add this property allows you web3.js ethes.js or by adding the parameters of a value of this attribute filter]

event Transfer(address indexed _from, address indexed _to, uint indexed amount);

indexedProperty is very important in the current filter solidity event [event name, set the parameters for the indexed index value, as a condition to determine the screening]:

A sender address filtering events

【非常重要】这里的事件名Transfer有三个参数,如果设置为null,代表所有【必须在solidity中定义为indexed的属性才支持】
let filter = this.contract_instance.filters.Transfer(this.active_wallet.address, null,null);
            this.contract_instance.on(filter, (from, to, value, event) => {
                console.log("监听发送以太坊事件:");
                console.log(`from:${from}+to:${to}+value:${value}`);
            });

 An address for the recipient filter events

【非常重要】这里的事件名Transfer有三个参数,如果设置为null,代表所有【必须在solidity中定义为indexed的属性才支持】
let filter = this.contract_instance.filters.Transfer(null, this.active_wallet.address,null);
            this.contract_instance.on(filter, (from, to, value, event) => {
                console.log("监听发送以太坊事件:");
                console.log(`from:${from}+to:${to}+value:${value}`);
            });

  Filter specifies the number of events [the events of default parameter is hex hexadecimal, so the screening, they also must be in hexadecimal]

【非常重要】这里的事件名Transfer有三个参数,如果设置为null,代表所有【必须在solidity中定义为indexed的属性才支持】
// 过滤value为100的事件
let filter = this.contract_instance.filters.Transfer(null,null,"0x100");
// 过滤value为数组中值的事件
let filter = this.contract_instance.filters.Transfer(null,null,["0x99","0x100","0x101"]);

            this.contract_instance.on(filter, (from, to, value, event) => {
                console.log("监听发送以太坊事件:");
                console.log(`from:${from}+to:${to}+value:${value}`);
            });

Guess you like

Origin blog.csdn.net/weixin_43343144/article/details/91502148