Body:
I’m developing a blockchain application and I’m encountering an error when trying to retrieve user data using Web3.js. Here are the details:
Solidity Struct Definition:
<code>`struct Account {
string name;
uint256 ID;
address accountAddress;
string username;
Status status;
UserRole role;
}`
</code>
<code>`struct Account {
string name;
uint256 ID;
address accountAddress;
string username;
Status status;
UserRole role;
}`
</code>
`struct Account {
string name;
uint256 ID;
address accountAddress;
string username;
Status status;
UserRole role;
}`
Function:
<code>function getUserByID(uint256 _ID)
public view onlyLevelOne returns (Account memory) {
address userAddress = accountIDs[_ID];
require(userAddress != address(0), "Admin not found");
return accounts[userAddress];
}
</code>
<code>function getUserByID(uint256 _ID)
public view onlyLevelOne returns (Account memory) {
address userAddress = accountIDs[_ID];
require(userAddress != address(0), "Admin not found");
return accounts[userAddress];
}
</code>
function getUserByID(uint256 _ID)
public view onlyLevelOne returns (Account memory) {
address userAddress = accountIDs[_ID];
require(userAddress != address(0), "Admin not found");
return accounts[userAddress];
}
JavaScript Code
<code>searchUser: async function() {
$('#searchUserButton').prop('disabled', true);
const ID = document.getElementById('ID').value;
try {
const instance = await App.contracts.SecureEvidence.deployed();
console.log('Contract instance:', instance);
// Call getUserByID function using Web3.js
const result = await instance.getUserByID(ID, { from: App.account });
console.log('Raw result:', result);
} catch (error) {
console.error('Error retrieving user data:', error);
showErrorModal('Error retrieving user data: ' + error.message);
} finally {
$('#searchUserButton').prop('disabled', false);
}
}
</code>
<code>searchUser: async function() {
$('#searchUserButton').prop('disabled', true);
const ID = document.getElementById('ID').value;
try {
const instance = await App.contracts.SecureEvidence.deployed();
console.log('Contract instance:', instance);
// Call getUserByID function using Web3.js
const result = await instance.getUserByID(ID, { from: App.account });
console.log('Raw result:', result);
} catch (error) {
console.error('Error retrieving user data:', error);
showErrorModal('Error retrieving user data: ' + error.message);
} finally {
$('#searchUserButton').prop('disabled', false);
}
}
</code>
searchUser: async function() {
$('#searchUserButton').prop('disabled', true);
const ID = document.getElementById('ID').value;
try {
const instance = await App.contracts.SecureEvidence.deployed();
console.log('Contract instance:', instance);
// Call getUserByID function using Web3.js
const result = await instance.getUserByID(ID, { from: App.account });
console.log('Raw result:', result);
} catch (error) {
console.error('Error retrieving user data:', error);
showErrorModal('Error retrieving user data: ' + error.message);
} finally {
$('#searchUserButton').prop('disabled', false);
}
}
Error Message:
Error retrieving user data: invalid solidity type!: tuple
Additional Information:
<code>Solidity Compiler Version: (specify your version, e.g., 0.8.0)
Web3.js Version: (specify your version, e.g., 1.3.6)
Ethereum Environment: (e.g., Ganache, Ropsten Testnet)
</code>
<code>Solidity Compiler Version: (specify your version, e.g., 0.8.0)
Web3.js Version: (specify your version, e.g., 1.3.6)
Ethereum Environment: (e.g., Ganache, Ropsten Testnet)
</code>
Solidity Compiler Version: (specify your version, e.g., 0.8.0)
Web3.js Version: (specify your version, e.g., 1.3.6)
Ethereum Environment: (e.g., Ganache, Ropsten Testnet)
how i can get return deta to the result variable
New contributor
juthindu vijayabandara is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.