I have been getting a weird errored: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.1.2)
error when testing contract functions in Remix, even though it goes through without revert. After debugging and stripping most of the logic, I found a minimal example to reproduce this problem:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts@4.1.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.1.0/token/ERC20/ERC20.sol";
contract Test is ERC721 {
constructor() ERC721("TEST", "TEST") { }
function test() public {
emit Transfer(address(0), address(0), 100);
}
}
The test()
call would produce an error
transact to Test.test pending ...
transact to Test.test errored: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.1.2)
Looking closer, I can see that both OpenZeppelin’s ERC20 and ERC721 contracts provide a Transfer
Event. To verify this assumption, I commented out //import "@openzeppelin/contracts@4.1.0/token/ERC20/ERC20.sol";
and the event emit works as expected. Because my contract uses ERC20 to instantiate an instance of a token so I need to import the definitions, but I am confused if this is a bug in Remix or by design a Solidity contract should not import two files with the same Event names? Is there any way to organize imports to get rid of this problem?