Invalid bytes string given: undefined
Description
The issue is related to calling a contract method from another contract and the events fired from that second contract. The contracts in question are an ERC20 and ERC721. When I call a method in the ERC721 that then calls the transfer method in ERC20, I will get the error in the title when trying to decode the logs.
After much exploring of the open issues with similar titles and the web3-eth-abi source code I have a theory to what is happening:
ERC20 has a Transfer event WITHOUT an indexed _value parameter. ERC721 has a Transfer event WITH indexed _tokenId. When I call the method in the ERC721 that then calls the method in ERC20, the ERC20 contract fires a Transfer event that is then decoded using the ERC721 abi, not the ERC20 abi.
Expected behavior
No error
Actual behavior
Invalid bytes string given: undefined
Steps to reproduce the behavior
Using the following Contracts:
pragma solidity ^0.5.0;
import 'openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol';
import 'openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol';
contract TheERC20Token is ERC20Detailed, ERC20Mintable {
bool public v07 = true;
constructor(string memory name, string memory symbol, uint8 decimals)
public
ERC20Detailed(name, symbol, decimals)
{
}
}
and the ERC721 contract:
pragma solidity ^0.5.0;
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol';
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol';
import 'openzeppelin-solidity/contracts/ownership/Ownable.sol';
import './TheERC20Token.sol';
contract Eventer is ERC721Full, ERC721Mintable, Ownable {
bool public v06 = true;
TheERC20Token USDP;
uint256 public numTickets;
uint256 public ticketPrice;
uint256 public ticketsSold = 0;
address public tokenAddress;
constructor(
string memory _name,
string memory _symbol,
uint256 _numTickets,
uint256 _ticketPrice
)
ERC721Full(_name, _symbol)
public
{
numTickets = _numTickets;
ticketPrice = _ticketPrice;
USDP = TheERC20Token(0xFf6d8327d47972073457F29858A8EBFdb0188aF6);
tokenAddress = 0xFf6d8327d47972073457F29858A8EBFdb0188aF6;
}
function redeemFunds() public onlyOwner {
uint256 _balance = USDP.balanceOf(address(this));
require(USDP.transfer(owner(),_balance));
// USDP.transfer(owner(),_balance);
}
}
and using the following code to call the function:
contract = new web3.eth.Contract(artifact.abi,artifact.address)
contract.transactionConfirmationBlocks = 3
const toSend = contract.methods[methodName](...args)
const gas = await toSend.estimateGas({from})
toSend.send({from,gas})
.on('confirmation', (confirmationNumber, receipt) => {
})
.on('receipt', (receipt) => {
alert('RECEIPT'+JSON.stringify(receipt))
})
.on('error', (err) => alert(err.message))
.then(
m => alert(JSON.stringify(m))
)
Error Logs
Invalid bytes string given: undefined
decodeParameters
web3-eth-abi.umd.js:64:28
decodeParameter
web3-eth-abi.umd.js:53:39
<unknown>
web3-eth-abi.umd.js:112:46
decodeLog
web3-eth-abi.umd.js:105:25
decode
web3-eth-contract.umd.js:226:58
<unknown>
web3-eth-contract.umd.js:635:54
afterExecution
web3-eth-contract.umd.js:634:34
<unknown>
web3-core-method.umd.js:1069:72
__tryOrUnsub
Subscriber.js:205:20
complete
Subscriber.js:190:38
_complete
Subscriber.js:96:8
complete
Subscriber.js:78:12
_callee2$
web3-core-method.umd.js:425:22
tryCatch
runtime.js:62:44
invoke
runtime.js:288:30
asyncGeneratorStep
asyncToGenerator.js:3:24
_next
asyncToGenerator.js:25:27
tryCallOne
core.js:37:14
<unknown>
core.js:123:25
_callTimer
JSTimers.js:152:14
_callImmediatesPass
JSTimers.js:200:17
callImmediates
JSTimers.js:464:30
__callImmediates
MessageQueue.js:320:6
<unknown>
MessageQueue.js:135:6
__guard
MessageQueue.js:297:10
flushedQueue
MessageQueue.js:134:17
Gists
Versions
- web3.js: [email protected]
- nodejs:
- browser:
- ethereum node: Private testnet running Clique
Hey! Thanks for taking a look at the issue, but I don't think this is a Feature Request.
My app crashes because the web-eth-abi file throws an error when bytes are undefined. My workaround was to wrap the decoder in a try catch block so that if it does return bytes as undefined it doesnt throw an error, like this:
web3-eth-abi.umd.js line 105
inputs.forEach(function (input, i) {
try {
if (input.indexed) {
if (input.type === 'string') {
return;
}
value = topics[topicCount];
if (_this.isStaticType(input.type)) {
value = _this.decodeParameter(input.type, topics[topicCount]);
}
returnValues[i] = value;
returnValues[input.name] = value;
topicCount++;
return;
}
nonIndexedInputKeys.push(i);
nonIndexedInputItems.push(input);
} catch(err) {
console.log('FOR TESTING PURPOSES '+err.message+' [ web3-eth-abi 123]')
}
});
A Feature Request might be to be able to read what is returned in this case, but having it throw an error is a bug.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment, otherwise this issue will be closed in 7 days