1

I am simply trying to console.log the array in solidity using 'hardhat/console.sol'

uint8[3] memory myArr = [1,2,43]; console.log(myArr);

I am facing below error:

TypeError: Member "log" not found or not visible after argument-dependent lookup in type(library console).

3 Answers 3

0

I haven't been using hardhat console for a while, but I do not remember I had an issue with it except it was used only for single values - not arrays or structs. Please double check the official documentation.

I would also suggest to do a test coverage for your use case, this approach made console log almost redundant. This is part of docs which covers this topic.

0

You're seeing this issue because the function log(uint8[] memory) doesn't exist. Read through the hardhat/console.sol implementation to see the available functions.

The simplest way to do what you want is probably to loop over the array, casting each entry to a uint256, and call console.log(value) (the full signature being log(uint256)) for each entry.

0

The error you are encountering is due to the fact that the console.sol library does not have a function with the name log. To log an array in Solidity, you can use a loop and log each element individually. Here's an example:

uint8[3] memory myArr = [1,2,43]; for (uint8 i = 0; i < myArr.length; i++) { console.log(myArr[i]); }

Alternatively, you can convert the array to a string and log the entire string using console.log(abi.encodePacked(myArr)). Note that this method may not work if the array contains non-primitive values.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.