I am trying to connect two different Smart Contracts using interfaces. Here is my contract CRUD.sol
:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4;
contract CRUD {
struct Data {
uint id;
bytes32 contentHash;
string description;
}
// Variables de estado
Data[] data;
uint nextId;
// Operaciones CRUD: CREATE, READ, UPDATE y DELETE:
// Operación CREATE
function createData(string memory _description) public{
bytes32 contentHash = createHash(_description);
data.push(Data(nextId, contentHash, _description));
nextId++;
}
// Operación READ por búsqueda del id
function readData(uint _id) public view returns (uint, bytes32,string memory) {
uint index = findIndex(_id);
return (data[index].id, data[index].contentHash, data[index].description);
}
// Operación READ por búsqueda del hash de la entrada de datos
function readDataByHash(bytes32 _hash) public view returns (uint, bytes32,string memory) {
uint index = findByHash(_hash);
return (data[index].id, data[index].contentHash, data[index].description);
}
//Operacion READ todos las entradas de datos
function readAllData() external view returns (Data[] memory){
return data;
}
function count() external view returns (uint){
return data.length;
}
// Operación UPDATE
function updateData(uint _id, string memory _description) public returns (uint, bytes32, string memory){
uint index = findIndex(_id);
bytes32 contentHash = createHash(_description);
data[index].contentHash= contentHash;
data[index].description = _description;
return (data[index].id, data[index].contentHash, data[index].description);
}
// Operación DELETE
function deleteData(uint _id) public{
uint index = findIndex(_id);
delete data[index];
}
// Creación del hash
function createHash(string memory _description) internal pure returns (bytes32){
return keccak256(abi.encodePacked(_description));
}
// Búsqueda del id
function findIndex(uint _id) internal view returns (uint) {
for (uint i = 0; i < data.length; i++) {
if (data[i].id == _id) {
return i;
}
}
revert("Data not found");
}
// Busqueda por el hash de la entrada de datos
function findByHash(bytes32 _contentHash) internal view returns (uint) {
for (uint i = 0; i < data.length; i++) {
if (data[i].contentHash == _contentHash) {
return i;
}
}
revert("Data not found");
}
}
Here is the other contract:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4;
interface ICRUD{ function readAllData() external view returns (Data[] memory); }
contract verifyData{
function read() external view returns (Data[] memory){
Data[] data = ICRUD(0xd9145CCE52D386f254917e481eB44e9943F39138).readAllData();
return data;
}
}
My purpose is to call readAllData function from verifyData contract but Remix just keeps returning the following error:
DeclarationError: Identifier not found or not unique.
--> verifyData.sol:5:51:
|
5 | function readAllData() external view returns (Data[] memory);
| ^^^^
Can someone help me? Thanks