Binance Smart Chain TestNet contract deployment JSON RPC error execution Reverted - blockchain

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.

Related

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).

Using Ganache provided address but still unable to vote

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.

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.

To interact with smart contract without gasprice

I am using web3j java library to deploy and to interact with the smart contract. When I tried to send a transaction that invoke a function in smart contract by setting the gas price to 0 and gas limit to DefaultGasProvider.GAS_LIMIT. I am getting the below exception.
How to fix this issue?
With Remix and MetaMask it works without any issue. What am I missing when using web3j, any pointers would be of great help.
org.web3j.protocol.exceptions.TransactionException: Transaction has failed with status: 0x0. Gas used: 4300000. (not-enough gas?)
Only solidity ^0.4.25 supports sending transactions with gas price 0.