truffle serve throws the below mentioned error? - ethereum

:\blockchain\truffle\demo\mortgage-blockchain-demo>truffle serve
erving static assets in .\build on port 8080...
ebuilding...
:\Users\Mabel\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:220
48
return (new fsevents(path)).on('fsevent', callback).start();
^
ypeError: fsevents is not a constructor
at createFSEventsInstance (C:\Users\Mabel\AppData\Roaming\npm\node_modules\t
uffle\build\cli.bundled.js:220548:11)
at setFSEventsListener (C:\Users\Mabel\AppData\Roaming\npm\node_modules\truf
le\build\cli.bundled.js:220602:16)
at FSWatcher.FsEventsHandler._watchWithFsEvents (C:\Users\Mabel\AppData\Roam
ng\npm\node_modules\truffle\build\cli.bundled.js:220766:16)
at FSWatcher.<anonymous> (C:\Users\Mabel\AppData\Roaming\npm\node_modules\tr
ffle\build\cli.bundled.js:220900:25)
at LOOP (fs.js:1758:14)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
kindly help me in resolving the issue . I am running on a windows 7 machine .
trying to do ethereum truffle setup.

Just remove/off this below code in //Users/**abc/projectFolder/node_modules/chokidar/lib/fsevents-handler.js
function createFSEventsInstance(path, callback) {
//return (new fsevents(path)).on('fsevent', callback).start();
}

Disable the FsEvents when not used:
C:\Users\UserName\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js
// if (!FsEventsHandler.canUse())
opts.useFsEvents = false;
Steps:
truffle compile && truffle build && truffle migrate && truffle serve

scene:
using create-react-app
/Users/**abc/projectFolder/node_modules/chokidar/lib/fsevents-handler.js
Solution:
Temporarily //return (new fsevents(path)).on('fsevent', callback).start();

Related

Receiving "invalid or does not take any parameters" when attempting to deploy a contract

here is my 2_deploy_contract.js syntax
const DerbyToken = artifacts.require("./DerbyToken.sol");
module.exports = function(deployer) {
// Deploy the Migrations contract as our only task
deployer.deploy(DerbyToken);
};
after I migrate the file using truffle I receive this error message
Error: Migration /home/cyraidz/token_sale/migrations/2_deploy_contracts.js invalid or does not take any parameters
at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:55:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.3.5 (core: 5.3.5)
Node v10.19.0
Add a newline at the end of "2_deploy_contract.js"

Truffle Smart Contract Error: Invalid number of parameter

I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains
Now I want to migrate the SimpleStorage.sol Smart Contract to the blockchain, but I want to make it to add the "PrivateFor" parameter.
This is my Smart Contract:
pragma solidity ^0.4.17;
contract SimpleStorage {
uint public storedData;
constructor(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() view public returns (uint retVal) {
return storedData;
}
}
This is my: 2_deploy_simplestorage.js
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42, {privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
But when I do truffle migrate, I get this error:
$ truffle migrate
⚠️ Important ⚠️
If you're using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.
Starting migrations...
======================
> Network name: 'development'
> Network id: 10
> Block gas limit: 3758096384
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0x0a55cd010bb30247c3ae303e54be8dd13177b520af5967728cf77e07ca9efe76
- Blocks: 0 Seconds: 0
> Blocks: 0 Seconds: 0
> contract address: 0x1932c48b2bF8102Ba33B4A6B545C32236e342f34
> account: 0xed9d02e382b34818e88B88a309c7fe71E65f419d
> balance: 1000000000
> gas used: 245462
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
- Saving migration to chain.
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
2_deploy_simplestorage.js
=========================
Deploying 'SimpleStorage'
-------------------------
Error: *** Deployment Failed ***
"SimpleStorage" -- Invalid number of parameters for "undefined". Got 2 expected 1!.
at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.1 (core: 5.0.1)
Node v8.11.4
When I don't add the "privateFor" parameter, it works:
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42)
};
But I need this privateFor parameter..
Does someone know how to fix this?
Hey #BlockChainProgrammer. Thanks for guiding me on how to use the Quorum proxy. It worked.
For this error, Try to upgrade/downgrade your truffle version to v4.1.
$ npm install -g truffle#4.1.10
and change the version of solidity to 0.4.24 in your truffle-config.js and the SimpleStorage.sol and add back privateFor in your migration file.
In this case of quorum, the
{
privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
was not defined in the contract, and at such the error, but that particular truffle compiler is compatible with Quorum features.
But For non-Quorum users like myself
The error Usually means, define a variable in your contract and not a compiler problem. Most likely a parameter not set in the constructor.
Open to corrections
Problem solved!
What I had to do is to downgrade truffle to "4.1.10" with:
truffle uninstall -g
and then
npm install -g truffle#4.1.10
Many thanks to #TS28

DeployedAddresses + Error: VM Exception while processing transaction: revert

I have a contract like following -
File Name: dummycontrat.sol
pragma solidity ^0.4.17;
contract DummyContract {
function fetchRandomNumber() public pure returns(uint) {
uint res = 10;
return res;
}
}
I have the following test file -
FileName: test/TestDummyContract.sol
pragma solidity ^0.4.17;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/dummycontract.sol";
contract TestDummyContract {
function testRandomNumberNew() public {
DummyContract dummyContract = new DummyContract();
uint randomNumber = dummyContract.fetchRandomNumber();
Assert.equal(randomNumber, 10, "Number is not 10");
}
function testRandomNumberDeployed() public {
DummyContract dummyContract = DummyContract(DeployedAddresses.DummyContract());
uint randomNumber = dummyContract.fetchRandomNumber();
Assert.equal(randomNumber, 10, "Number is not 10");
}
}
I run the command -
truffle compile && truffle migrate --reset --network dev && truffle test --network dev test/TestDummyContract.sol
The first test passes while the second gives an error. Logs from the truffle test command is following -
TestDummyContract
✓ testRandomNumberNew (53ms)
1) testRandomNumberDeployed
> No events were emitted
1 passing (894ms)
1 failing
1) TestDummyContract testRandomNumberDeployed:
Error: VM Exception while processing transaction: revert
at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Can anyone explain what's the problem here? I am running Ganache tool on OSX for the network.
DeployedAddresses.DummyContract() is failing because only contracts that are included in the Truffle deployment configurations are made available to DeployedAddresses. From the Truffle documentation:
The addresses of your deployed contracts (i.e., contracts that were deployed as part of your migrations) are available through the truffle/DeployedAddresses.sol library. This is provided by Truffle and is recompiled and relinked before each suite is run to provide your tests with Truffle's a clean room environment. This library provides functions for all of your deployed contracts, in the form of:
DeployedAddresses.<contract name>();
To fix your issue, you need to create the deployment configuration under /migrations (or add to your existing one, if you have it). For example:
2_deploy_contracts.js:
var DummyContract = artifacts.require("dummycontract");
module.exports = function(deployer) {
deployer.deploy(DummyContract);
};
Add that configuration, rerun truffle migrate --reset then your test will work.

Gcloud background functions with depedencies fail to deploy

Below is a basic example of gcloud background function with a dependency in it. On using uuid package it throws up an error although package.json has uuid
On deploying following erros is received.
gcloud beta functions deploy helloPubSub --trigger-resource my-topic --trigger-event google.pubsub.topic.publish
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'uuid'
index.js
const uuid = require('uuid');
exports.helloPubSub = (event, callback) => {
const pubsubMessage = event.data;
const eventName = pubsubMessage.data ? Buffer.from(pubsubMessage.data, 'base64').toString() : 'World';
console.log(eventName,uuid.v4());
callback();
};
package.json
"dependencies": {
"uuid": "^3.2.1"
},
There was an issue in my .gcloudignore
Below change did make it work!
From
node_modules/
to
node_modules

Gulp Build command is failing with error " EISDIR: Illegal operation on directory"

I am trying to run the gulp build task for the dev environment on the server but its failing. However, The same gulp build is working on my local machine. The function and error are given below.
Function:
// S3 Upload for dev
gulp.task('s3sync:dev', function () {
var config = {
accessKeyId: "-Key-",
secretAccessKey: "-Key-"
};
var s3 = require('gulp-s3-upload')(config);
return gulp.src("./dist/**")
.pipe(s3({
Bucket: 'example',
ACL: 'public-read'
}, {
maxRetries: 5
}))
});
Command:
Gulp build:development
Error:
[09:01:04] Starting 's3sync:dev'...
events.js:160
throw er; // Unhandled 'error' event
^
Error: EISDIR: illegal operation on a directory, read
at Error (native)
Any idea?
Finally, This problem has been solved by removing a system symlink which was created after the deployment from the capistrano which is also running below npm commands.
npm run clean && npm run build
After removing the system file. I have run the below command and it works fine.
gulp build:development