OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Invalid Solidity Type Error When Retrieving Struct Data in Web3.js "invalid solidity type!: tuple"

  • Thread starter Thread starter juthindu vijayabandara
  • Start date Start date
J

juthindu vijayabandara

Guest
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;
}`

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];
}

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);
    }
}

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)

how i can get return deta to the result variable

<p><strong>Body:</strong></p>
<p>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:
<strong>Solidity Struct Definition:</strong></p>
<pre><code>`struct Account {
string name;
uint256 ID;
address accountAddress;
string username;
Status status;
UserRole role;
}`
</code></pre>
<p><strong>Function:</strong></p>
<pre><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></pre>
<p><strong>JavaScript Code</strong></p>
<pre><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></pre>
<p><strong>Error Message:</strong></p>
<p>Error retrieving user data: invalid solidity type!: tuple</p>
<p><strong>Additional Information:</strong></p>
<pre><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></pre>
<p>how i can get return deta to the result variable</p>
 

Latest posts

Top