interface IExampleInterface {
event Deposit(address indexed sender, uint256 amount);
}
contract ExampleContract is IExampleInterface {
function deposit() external payable {
emit Deposit(msg.sender, msg.value);
}
}
contract ParentContract {
event NewNumber(uint256 number);
function doSomething(uint256 number) public {
emit NewNumber(number);
}
}
contract ChildContract is ParentContract {
pragma solidity ^0.8.15;
contract ExampleContract {
event SomeEvent(uint256 blocknum, uint256 indexed timestamp);
function selector() external pure returns (bool) {
// true
return SomeEvent.selector == keccak256("SomeEvent(uint256,uint256)");
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```solidity | |
pragma solidity ^0.8.15; | |
contract ExampleContract { | |
event SomeEvent(uint256 blocknum, uint256 indexed timestamp); | |
function selector() external pure returns (bool) { | |
// true | |
return SomeEvent.selector == keccak256("SomeEvent(uint256,uint256)"); |
pragma solidity ^0.8.15;
contract ExampleContract {
event SomeEvent(uint256 blocknum, uint256 timestamp) anonymous;
function selector() public pure returns (bool) {
// ERROR: does not compile, anonymous events don't have selectors
return SomeEvent.selector == keccak256("SomeEvent(uint256,uint256)");
op code | Usage |
---|---|
log0(p, s) | log without topics and data mem[p…(p+s)) |
log1(p, s, t1) | log with topic t1 and data mem[p…(p+s)) |
log2(p, s, t1, t2) | log with topics t1, t2 and data mem[p…(p+s)) |
log3(p, s, t1, t2, t3) | log with topics t1, t2, t3 and data mem[p…(p+s)) |
log4(p, s, t1, t2, t3, t4) | log with topics t1, t2, t3, t4 and data mem[p…(p+s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers'); | |
const tokenAddress = '0x...'; | |
const filterAddress = '0x...'; | |
const tokenAbi = [ | |
// ... | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ethers } = require("ethers"); | |
// const provider = your provider | |
const abi = [ | |
"event Transfer(address indexed from, address indexed to, uint256 value)" | |
]; | |
const tokenAddress = "0x..."; | |
const contract = new ethers.Contract(tokenAddress, abi, provider); |
contract ExampleContract {
// We will explain the significance of the indexed parameter later.
event ExampleEvent(address indexed sender, uint256 someValue);
function exampleFunction(uint256 someValue) public {
emit ExampleEvent(sender, someValue);
}
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ethers } from "hardhat"; | |
async function main() { | |
const [user] = await ethers.getSigners(); | |
const data = "0x5197c7aa"; // function selector for the `getX` function | |
const Slot = await ethers.getContractFactory("Wrong"); | |
const slot = await Slot.deploy(); | |
await slot.deployed(); |