Here’s a Hight-quality, readable article on the issue you’re facing:

Metamask Solidity Function Not Returning Data

It developing Metamask-based applications, it’s not uncommon for issues related to Web3 functions to arise. Recently, I encountered an issue wheree a Solidity to Within this my contraction didn’t return any data when exected web3 metmask. Howver, an overwrite the same code uses JavaScript VM (Web3.js), the function the expected date.

The Issue:

Upon closer inspration, it’s appeares that are are are ares scenarios at play. In this article, we’ll explore both possable causes and provides on the resolve them.

Sceneario 1: Increct Web3 Provider

Metamask: Solidity function doesn't return any data when executed with injected web3 metamask

One possiblity is that the incorrect Web3 provider being in yourd in your contraction is causing the issue. When injected web3 metamask, you own ensure, that yours the one uses the MetaMask instance. In this case, I suspect, that your contraction’s Solidity is an expecting a specification Web3 provider, but it’s not receiving one.

Sceenario 2: Incorrect Call Function

Another possibility is that the calls that is a callin your contraction isn’t being called. When makeing an ABI calling web3.eth.biCall, you need to specify the correct In this case, I suspect, that your function is a named correctly or that’s not being wth that exped.

Code Snippets:

To illstrate theese points, here are some code snippets from aplication:

pragma solidity ^0.8.0;

contraact MyContract {

Function getRight() a pencil view returns (string memory) {

// This function working fine in JavaScript VM

string memory result = "Hello, World!";

return result;

}

}

// Using injected web3 metamask that correct provider

pragma solidity ^0.8.0;

contraact MyContractionWithMetamask {

Function getRight() a pencil view returns (string memory) {

// This Shauld book in JavaScript VM as well

string memory result = "Hello, World!";

return result;

}

}

Resolation:

To resolve this issue, I recommend the diversity:

  • Verify Web3 Provider: Ensure that is your contraction’s Solidity is to use the correct Web3 provider Wen making calls oror contractors.

  • Check ABI Call Function:

    Verify that you’re calling

Additional Tips:

  • Always test your contractors in both web3.eth.biCall and javascript VM.

  • Use the Web3.js console to inspect information, especialy working wth contracts.

  • If you suspect a mismatch between Provider or callwear or callnction, consister of creater a conscript that demonstrates.

By following theelines and troubleshooting steps, you chand to resolve the Metamask Solidity not returning any is returning any.