How to use older solc compilers with Truffle - ethereum

I am trying to reproduce the DAO attack that happened on Ethereum, however, I was not able to compile the DAO code. The current stable version of truffle does not support specifying a solc version.
I used the 5.0.0 beta 1 version for truffle, which supports specifying a solc version.
When compiling the DAO code, I get this error.
TypeError: Error parsing E:/Desktop/MetaCoin/contracts/DAO.sol: solc.compileStandard is not a function
at Object.parseImports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\parser.js:49:1)
at Object.getImports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:332:1)
at Promise.all.then.results (C:\Users\Administrator\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:305:1)
at <anonymous>
Any idea guys?

As of Truffle 5.0.0 beta -0, you can specify a solcjs version.
I have just tried it in my project and it works. Be sure to make the version number a string and use the following code:
module.exports = {
networks: {
... etc ...
},
compilers: {
solc: {
version: <string> // ex: "0.4.20". (Default: Truffle's installed solc)
}
}
};

Related

upgraded to latest nx workspace, test fail with transform

We are upgrading angular with nx workspace to latest
The problem is when we run test, we got following errors
feature-flag.mjs:93:20: ERROR: Transforming for-await loops to the configured target environment ("es2015") is not supported yet
feature-flag.mjs:184:4: ERROR: Transforming async generator functions to the configured target environment ("es2015") is not supported yet
The feature-flag library was build es2020, and our current App also on es2020 after upgrade.
The app using the feature-flag lib test fails with the error
I am not sure how to fix it
Things I have tried, in the App I have adjust tsconfig, tsconfig.app, tsconfig.spec to es2015 or es2017, but it didn't help.

Migration 2_deploy_contracts invalid or does not take any parameters at Object.run()

I am trying to compile my smart contracts using truffle pet-shop. I have the following contract in directory election/contracts/election.sol ;
pragma solidity >=0.4.0 <0.6.0;
contract Election{
string public candidate;
constructor() public{
candidate="Zeeshan";
}
}
The migration file to deploy contracts in directory election/migrations/2_deploy_contracts1.js is as follows;
var Election1=artifacts.require("election.sol");
module.export=function(deployer){
deployer.deploy(Election1)
};
I am using the following command to migrate the contracts:
truffle migrate
And I am getting the following results:
Compiling your contracts...
===========================
> Compiling .\contracts\Election.sol
> Compiling .\contracts\election.sol
> Artifacts written to D:\Notes\BCS\Semester 8\FYP\Practise Coding\dapp university 2 hr video code\election\build\contracts
> Compiled successfully using:
- solc: 0.5.8+commit.23d335f2.Emscripten.clang
Starting migrations...
======================
> Network name: 'development'
> Network id: 5777
> Block gas limit: 0x6691b7
2_deploy_contracts1.js
======================
Error: Error: Migration D:\Notes\BCS\Semester 8\FYP\Practise Coding\dapp university 2 hr video code\election\migrations\2_deploy_contracts1.js invalid or does not take any parameters
at Object.run (C:\Users\mk141\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:92:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.30 (core: 5.0.30)
Node v10.16.1
Its also compiling Election.sol because I renamed election.sol to Election.sol and it stores election.sol in cache perhaps.
As you can see above its giving Error:Migration 2_deploy_contracts invalid or does not take any parameters at Object.run() and i don't know how to resolve it.
I was making a mistake in 2_deploy_contracts1.js file. There is module.exports instead of module.export. So the new 2_deploy_contracts1.js file will be;
var Election1=artifacts.require("election.sol");
module.exports=function(deployer){
deployer.deploy(Election1)
};
Also, I was using the following command to migrate again;
truffle migrate
Instead, I should use the following command if I am migrating again;
truffle migrate --reset
We use this command because we already migrated our smart contracts in the built folder. This command will remove all previously migrated files in the built folder and add new migrated files of smart contracts.
In the require function you need to check the name of your contract like Election.sol and check for any typos

Failed to build Solidity contract: exec: "solc": executable file not found in $PATH

I'm executing below command:
abigen --sol helloworld.sol --pkg main --out helloworld.go
But getting below error:
Failed to build Solidity contract: exec: "solc": executable file not found in $PATH
When I check echo $PATH, solcjs is present.
echo $PATH
/home/edureka/go/bin:/usr/local/go/bin:/home/edureka/.local/share/umake/bin:/home/edureka/bin:/home/edureka/.local/bin:/home/edureka/.nvm/versions/node/v6.11.4/bin:/home/edureka/go/bin:/usr/local/go/bin:/home/edureka/.local/share/umake/bin:/home/edureka/bin:/home/edureka/.local/bin:/home/edureka/.local/share/umake/bin:/home/edureka/bin:/home/edureka/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/edureka/.nvm/versions/node/v6.11.4/bin/solcjs
How I can solve this error?
You have to install solc not solcjs.
https://solidity.readthedocs.io/en/v0.4.24/installing-solidity.html
The comandline options of solcjs are not compatible with solc and tools (such as geth) expecting the behaviour of solc will not work with solcjs.
You have to install a binary package - https://solidity.readthedocs.io/en/v0.4.24/installing-solidity.html#binary-packages
You should install solc. Check here.
This is mostly due to solc specific version not in your path.
To see which version of solc
solc --version
where is your solc installed ?
whereis solc
Add the output of the above command to your PATH.
export PATH=$PATH:{output_from_above_command}
This should resolve your solc not present in the PATH issue.
Please note that you need specific version tag. 0.7.6 or 0.8.0 etc... Any typos will not pick correctly.

async await not deploying in Google Cloud Functions

firebase deploy is giving me this error message:
async function asyncFunction() {
^^^^^^^^
SyntaxError: Unexpected token function
Here's my code:
async function asyncFunction() {
await getText2Speech(word, 'mp3', 'es-ES_EnriqueVoice')
}
asyncFunction();
getText2Speech is a 75-line function that runs perfectly when I call it without async or await.
I have the Node.js 8 runtime in my functions/package.json:
"engines": {
"node": "8"
},
I have Node up to date on my computer:
node -v
v11.2.0
It seems odd that the unexpected token is function, not async. It seems that firebase deploy recognizes async but I have the syntax wrong? es-lint can't find anything wrong with my code.
Could the problem be this:
npm list --depth 0 -g
├── UNMET PEER DEPENDENCY firebase-admin#6.2.0
npm ERR! peer dep missing: firebase-admin#~6.0.0, required by firebase-functions#2.1.0
If I roll back to firebase-admin#~6.0.0 will async await work?
The problem was that something was pointing to eslint v4.5.0, which doesn't support ES2017. I had eslint v5.9.0 installed but eslint -v always returned v4.5.0. I used find . -name 'eslint' to remove every copy of eslint, there were lots of versions, all other my computer. npm uninstall -g eslint doesn't get every copy of eslint. When eslint -v returned nothing then firebase deploy worked.
async/await was deploying on my other computer, then today it stopped deploying. I checked the package.json in the functions folder on both computers, and both were missing
"engines": {
"node": "8"
},
Adding this line, both computers now deploy async/await. I don't know how this object dropped out of the package.json file, and I don't know if this fix will continue to work, but I'll cross my fingers!

Gradle: Error listing versions of junit#junit;4.+

I am getting the below error when running gradle build on my gradle.properties file.
I know I am behind a firewall and I have a poxy I can use. I've tried adding the below to my gradle.properties file, but I cannot pull down jUnit. All help appreciated!
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
Error:
Error listing versions of junit#junit;4.+ using class
org.gradle.api.internal.artifacts.repositories.resolver.MavenVersionLister$1.
Will attempt an alternate way to list versions. This behaviour has been
deprecated and is scheduled to be removed in Gradle 2.0
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':testRuntime'.
> Could not resolve junit:junit:4.+.
Required by:
:HealthMonitor:1.0
> Failed to list versions for junit#junit;4.+.
> Could not list versions using M2 pattern 'http://repo1.maven.org/maven2/
[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]'.
> Could not GET 'http://repo1.maven.org/maven2/junit/junit/'.
> Connection to http://repo1.maven.org refused
build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Health Monitor', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Depending on the proxy, you may have to configure more than just the host and port. See Accessing the web via a proxy in the Gradle User Guide. Also, I recommend to try with a fixed version rather than a version range.