Using Ganache provided address but still unable to vote - blockchain

There is a function in my smart contract which I have deployed on local blockchain called
vote(uint _candidateId).
When calling this from truffle console
app.vote(1,{from : web3.eth.getAccounts().then(e=>{ return e[1]})})
It returns
Uncaught Error: Returned error: sender account not recognized
Although
web3.eth.getAccounts().then(e=>{ return e[1]})
returns an address that is provided by GANACHE and is known to GANACHE.
I can't solve this issue.

Related

view method in a smart contract changed to weird strings unintentionally

Hi I deployed a smart contract on Mumbai testnet and one of view methods in the contract suddenly stopped working as its name (or at least displayed) got weird like this.
cuº?TÔÿŇÃØ" #ra]„àU½{kYeCÀv`±m^‹c!ÀßedÌ+±'H¿%›©FIRST BLOCKCHAIN NOVEL
It was working fine yesterday when I deployed but today it stopped working so I checked the contract and found the above.
Deployed contract is here
Does anyone know what happened?
Could I fix it without deploying again?
In the front end app, I get this error.
Uncaught (in promise) Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="getAllNovels()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.4)
[update]
I deployed again and same thing happened...
contract is here
[console error]

Calling smart contract function to send ether to another address does not work when contract is deployed to hyperledger-besu

I have deployed a local hyperledger-besu test net and used truffle to migrate a very simple contract on the network. SimpleContract
I have prefunded some accounts so that I can interact with the contract. My genesis file is genesisFile
All the functions of the contract work well. However, when invoking the sendPayment function, I get an error errorImage
Here is the font end code I use to invoke the function codeImage
Please guide me on this. What am I doing wrong with the contract?

Note: The called function should be payable if you send value and the value you send should be less than your current balance

I'm trying to use ERC20 implementation of openzeppelin, but getting an error. tokenAddress is an address of the existing ERC20 token, for example USDC - 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0-solc-0.7/contracts/token/ERC20/ERC20.sol";
ERC20 token = ERC20(tokenAddress);
token.balanceOf(msg.sender);
An error
revert The transaction has been reverted to the initial state. Note:
The called function should be payable if you send value and the value
you send should be less than your current balance. Debug the
transaction to get more information.
The Remix VM emulator can't reach the contract deployed on the mainnet address - it's in a different environment.
However, you can fork the mainnet to your local environment, and then connect Remix to this local environment.
Here's an article describing how to fork the Ethereum mainnet using Ganache.
One-click solution based on the article:
ganache-cli --fork https://mainnet.infura.io/v3/{infura_project_id}
Then you can select a custom provider in your Remix IDE.
ganache-cli is listening on port 8545, and Ganache UI on 7545.
Enter the local "Web3 Provider Endpoint" address with the port number 8545 (ganache-cli) or 7545 (Ganache UI).

Binance Smart Chain TestNet contract deployment JSON RPC error execution Reverted

I have delopyed the MasterChef.sol smart contract at the address 0x852741C58ca084154201691CeB5B9D3312415C18 on the Bsc test net. When I call any other function except the owner it gives the error "call to MasterChef.poolLength errored: Error: Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }".
I am using remix IDE for this and I can't figure out what is the problem. It is something related to gas cost but I don't get what's wrong.
This is the contract code
https://github.com/sushiswap/sushiswap/blob/master/contracts/MasterChef.sol
while deploying the contract I first deployed the SushiToken.sol on BSC and then copied its address to pass as the first arg to the constructor, second arg dev was my copied clipboard metamask address third was 1000000000000000000000 fourth was 0 and the fifth was 1000000000000000000000 for the MasterChef.sol constructor.

MetaMask RPC error? 'MetaMask - RPC Error: Internal JSON-RPC error.'

I'm developing the front-end to an application that I'm trying to test. However, MetaMask keeps giving me this error? I tried changing the gas limit like previously suggested and nothing. Any ideas?
Error:
MetaMask - RPC Error: Internal JSON-RPC error.
code: -32603
data: {code: -32000, message: "gas required exceeds allowance (30000000) or always failing transaction"}
message: "Internal JSON-RPC error."
Without seeing the code, it's hard to say for sure but you could try:
Check any code you changed in the front end, specifically in your code you may have something like this:
const contractInstance = new state.web3.eth.Contract(
MyContract.abi,
"0x.....", // contract address
{
from: state.accounts[0],
gasPrice: 1000,
gas: 100000
}
);
Make sure the gas prices are similar to those, you may have to adjust for your case.
Re-compile and redeploy --> for truffle, run truffle develop first, then compile then migrate --reset for local deployment.
In Metamask, reset your test account. Metamask > Select Account > Settings > Advanced > Reset account. Only do this for testing accounts
Previously it used to happen in older versions due to a gas specification issue which was fixed. rpcErrors.internal` expects a string as the first argument, with arbitrary data being the optional second argument. Passing in a non-
string first argument results in the error being shadowed by an error
from eth-json-rpc-errors.
Please check what you are passing to Metamask.
In my case, after trying so many options I have restarted Ganache and re-imported new account from Ganache to Metamask.
I connected this new account with localhost application.
This resoles my issue.
Before performing any transaction the sending ETH address must be connected to your own site or UI. So it can get the address of sending account and goes towards the further transaction in the metamask.
Make sure Your sending account address must be connected to your UI.