Error: Method eth_compileSolidity not supported - ethereum

ENV:
test-rpc
truffle
code:
let source = "pragma solidity ^0.4.11;contract Calc{ uint count; function add(uint a, uint b) returns(uint){ count++; return a + b; } function getCount() returns (uint){ return count; }}";
let calc = web3.eth.compile.solidity(source);
The terminal tell me:
truffle(development)> Error: Error: Method eth_compileSolidity not supported.
at GethApiDouble.handleRequest (/Users/user/.nvm/versions/node/v6.10.3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:101870:16)
......

I guess you trying to obtain ABI and/or bytecode of your contract.
Web3 library (which you require in truffle console and then instantiating web3 provider) has no web3.eth.compile.solidity() since version 1.6.0
Here described compiling ways using Remix and solc compiler: https://ethereum.stackexchange.com/questions/15435/how-to-compile-solidity-contracts-with-geth-v1-6
When truffle compiles your code it uses some fixed version of solc (depending on truffle version). For truffle 3.2.5 solc 0.4.11+commit.68ef5810.Emscripten.clang used. Here's the way how to get current version of truffle's solc (it's neccessary to know when you verifying code on Etherscan): https://ethereum.stackexchange.com/questions/18133/how-do-i-find-the-exact-solidity-compiler-version-used-by-truffle

Related

Why the bytecodes for the same smart contract in testnet explorer and Remix/solcjs are different?

I am using Remix to compile and deploy my smart contract to Rinkeby and RSK test networks.
I don't understand why the bytecode of my contract on Rinkeby explorer is different from the metadata.data.deployedBytecode.object in Remix artifacts and also different from evm.deployedBytecode.object coming from solcjs compiler. I also tried this on RSK and I got the same issue.
That's what I do in Remix:
I create a MegaHonk.sol file in contracts folder
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;
contract MegaHonk {
uint256 public count;
event LoudSound(address indexed source);
function honk() external {
require(tx.origin != msg.sender, 'EOA not allowed');
count += 1;
emit LoudSound(tx.origin);
}
}
I select the appropriate compiler version 0.8.7, select Environment: Injected provider - Metamask, compile and deploy to Rinkeby. The contract successfully deploys. Then I go to Rinkeby explorer, find my contract bytecode and compare it with the one in remix-file-explorer/contracts/artifacts/MegaHonk.js in the metadata.data.deployedBytecode.object property.
Bytecode from Rinkeby is 1348 symbols long and
Bytecode from Remix is 1350 symbols long.
The exact same thing happens when I am compiling the same smart contract with solcjs compiler. I use the right version 0.8.7 and these input parameters:
const input = {
language: 'Solidity',
settings: {
outputSelection: {
'*': {
'*': ['evm.deployedBytecode', 'evm.bytecode'],
},
},
optimizer: {
enabled: false,
},
},
sources: {
'MegaHonk.sol': {
content: MegaHonk,
},
},
};
Why does this happen? What compiler parameters should I use to make the bytecodes identical in the Remix artifacts, solcjs compiler and in blockchain explorer (Ethereum or RSK testnets)?

Why is the open zeppelin Safe Math contract not importing?

I am using the following contract from Ethernaut and did sudo npm i #openzeppelin/contracts
pragma solidity 0.6.0;
import "#openzeppelin/contracts/math/SafeMath.sol";
contract CoinFlip {
using SafeMath for uint256;
uint256 public consecutiveWins;
uint256 lastHash;
uint256 FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968;
constructor() public {
consecutiveWins = 0;
}
function flip(bool _guess) public returns (bool) {
uint256 blockValue = uint256(blockhash(block.number.sub(1)));
if (lastHash == blockValue) {
revert();
}
lastHash = blockValue;
uint256 coinFlip = blockValue.div(FACTOR);
bool side = coinFlip == 1 ? true : false;
if (side == _guess) {
consecutiveWins++;
return true;
} else {
consecutiveWins = 0;
return false;
}
}
}
However, I'm still getting this error regarding SafeMath contract not being found even after installing all the openzeppelin contracts: Error: Could not find #openzeppelin/contracts/math/SafeMath.sol from any sources
My configurations below:
Truffle v5.1.39 (core: 5.1.39)
Solidity - 0.6.0 (solc-js)
Node v16.13.1
Web3.js v1.2.1
The problem is your version selection.
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/solc-0.6/contracts/utils/SafeCast.sol";
This one is for solidity 0.6.0 the version you are currently using.
but you are using
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol
which is for solidity >= 0.8.0
When you install openzeppelin contracts with npm as you did, you install the version with the current tag. The current tag is right now at Solidity version ^0.8.0. Since version 0.8+, you don't need to use SafeMath anymore as it is implemented on the language level.
As you are using Solidity version 0.6 you should also install the openzeppelin package for this version. This should be 3.4.1. You can install this version with the following command:
npm i #openzeppelin/contracts#3.4.1
The better solution, however, would be to update your contract to solidity version 0.8+, use the current openzeppelin implementation and remove SafeMath library.

Solidity Internal exception in StandardCompiler

This is the source code
pragma solidity ^0.5.1;
contract myContract{
string value;
constructor() public {
value = "myValue";
}
function get() public view returns(string memory){
return value;
}
function set(string memory _value) public{
value = _value;
}
}
Selected Compiler on Remix IDE is 0.5.1+commit.c8a2cb62
Selected Environment is Javascript VM
When I compile the command I get this error
Internal exception in StandardCompiler::compileInternal: /root/project/libevmasm/ExpressionClasses.cpp(187): Throw in function ExpressionClasses::Id dev::eth::ExpressionClasses::tryToSimplify(const dev::eth::ExpressionClasses::Expression &)
Dynamic exception type: boost::exception_detail::clone_impl<dev::eth::OptimizerException>
std::exception::what: Rule list not properly initialized.
[dev::tag_comment*] = Rule list not properly initial
However this error does not pop up for same source code if I select the compiler as 0.5.11
Other users are saying that they are getting this error on pre 0.5.3 compilers.
This is a bug in a certain version of the compiler - it does not work properly if the javascript runtime environment does not provide enough stack space or memory. It should work with the most recent compilers.
Check this thread for more info

One of ethereum solidity methods is not working properly got error Returned values aren't valid, did it run Out of Gas

I'm trying to deploy a solidity program to my private ethereum network. However, when i call a method it's not working properly.
This is what i'vd done before the call method.
$ truffle console
truffle(development)> var dApp
undefined
truffle(development)> Hello.deployed().then(function(instance) { dApp = instance; })
undefined
truffle(development)> dApp.message.call()
test env is below
truffle#5.0.28
solc#0.5.10
linux centOS 7
geth#1.8.23
I tried all of the solution in answer about the below error in stack overflow, but it didn't work.
Weird thing is that I installed geth on my macos using same release version, but its version was different from what I've installed on my centOS. It's 1.8.27 on macos and 1.8.23 on centOS 7.
By the way, it was working well when I tried same progress on my macos.
Its return is below.
truffle(development)> dApp.message.call()
'Hello, World : This is a Solidity Smart ' +
'Contract on the Private Ethereum ' +
'Blockchain'
Bammmmmmmmmmmm.
This below is a solidity program I deploied.
pragma solidity >=0.4.15 <0.6.0;
contract Hello {
string public message;
function HelloEth() public {
message = "Hello, World : This is a Solidity Smart Contract on the Private Ethereum Blockchain";
}
}
This is the error returned.
Thrown:
Error: Returned values aren't valid, did it run Out of Gas?
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:318:1)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:208:1)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-providers-http/src/index.js:96:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:112:1
at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3-core-requestmanager/src/index.js:147:1
at sendTxCallback (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/~/web3-core-method/src/index.js:473:1)
at Method.formatOutput (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/~/web3-core-method/src/index.js:163:1)
at Method.outputFormatter (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/src/index.js:818:1)
at Contract._decodeMethodReturn (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/src/index.js:465:1)
at ABICoder.decodeParameters (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-abi/src/index.jsa:226:1)
I really want to know because i tried almost 1 months... if you have any idea or any solution please let me know. :(
I also ran into a similar problem, after I posted it in Geth Github, they indicated that the problem may be caused by the latest Solidity compilers which depend on features introduced in Constantinople.
Thus, you might need to add "constantinopleBlock": 0 in your genesis.json to let your private blockchain identify what solidity version you used.
"config": {
"chainId": 1515,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"clique": {
"period": 2,
"epoch": 30000
}
},...
All variables which you defined as public it will always becoming a methods. so, you can access/call your public variable as same as calling a method in smart contract.

Truffle migrate success but contract address is not displayed

I am using testrpc to deploy my contracts. Contract deployment is successful and it also displays the contract address in console when it is deployed.
But when I try to query from truffle console it throws this error: Contract has no network configuration for its current network id (5777).
I am clueless. Any help would be much appreciated. I am using Truffle v4.1.0-beta.0 (core: 4.1.0).
Solidity v0.4.19 (solc-js)
You need to return the the deployed contract from the Promise to have the contract object be injected by Truffle. Example:
var Caller = artifacts.require("Caller");
var Callee = artifacts.require("Callee");
module.exports = function(deployer) {
deployer.deploy(Callee).then(function() {
return deployer.deploy(Caller, Callee.address);
});
};