Truffle Smart Contract Error: Invalid number of parameter - ethereum

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

Related

Uniswap swapRouter02 Error: Transaction reverted without a reason string

I'm testing uniswap's swap transaction
my new contract swap() -> uniswap swapRouter02 contract exactInputSingle() which is not from wallet to contract swap
Specifically below code is trying swap my contract's 0.08 WETH to some UNI. and I checked my contract has 0.08 weth.
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 => WETH token address
0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 => UNI token address
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 => Uniswap SwapRouter02 contract address
but error message when try
ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);
Error: Transaction reverted without a reason string at ~~
what does this message mean? and how can I debug this error?
My test environment is hardhat local forking mainnet. The error message is from hardhat forking mainnet
hardhat: {
chainId: 31337,
forking: {
url: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,
blockNumber: 14390000
},
},
function swap() external payable override lock returns (uint256) {
//approve
address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).call(abi.encodeWithSelector(IERC20.approve.selector, 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45, 0x011C37937E080000));
//test
uint256 amountOut;
ISwapRouter02.ExactInputSingleParams memory params =
IV3SwapRouter.ExactInputSingleParams({
tokenIn: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
tokenOut: 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984,
fee: 0,
recipient: msg.sender,
//deadline: _params.deadline,
amountIn: 0x011C37937E080000, //0.08
amountOutMinimum: 0x0,
sqrtPriceLimitX96: 0
});
ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);
return 1;
}
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="Error: Transaction reverted without a reason string", method="estimateGas", transaction={"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","to":"0xd5a946A0C214d732a8cf5678be593d26E1bf2170","data":"0x50ac1dd900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f984000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000001c6bf526340000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000021231000000000000000000000000000000000000000000000000000000000000","accessList":null}, error={"name":"ProviderError","code":-32603,"_isProviderError":true,"data":{"message":"Error: Transaction reverted without a reason string","data":"0x"}}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
I found my fault,
reason was amountOutMinimum value must be not 0x0

How to fix 'Truffle Migrate' bytecode undefined error

Spent a few hours trying to figure this out - hoping someone has encountered this. (in testing) All the testing files run.
When running truffle migrate --reset it logs the below.
Versions that may be useful are Truffle v5.1.58 (core: 5.1.58), Node v12.13.0 and also using pragma solidity >=0.6.0 for all smart contracts contracts.
EDIT:
Have tried all sorts at this point. Different coompilers, using solcjs and just solc - no dice.
Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./src/contracts/Exchange.sol
> Compiling ./src/contracts/Migrations.sol
> Compiling ./src/contracts/Token.sol
> Compiling openzeppelin-solidity/contracts/math/SafeMath.sol
✔ Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /Users/tony/Desktop/blockchain/el-capitan-exchange/src/abis
> Compiled successfully using:
- solc: 0.6.12+commit.27d51765.Emscripten.clang
Starting migrations...
======================
> Network name: 'development'
> Network id: 5777
> Block gas limit: 6721975 (0x6691b7)
1_initial_migration.js
======================
Replacing 'Migrations'
----------------------
> transaction hash: 0x1ce9b2b65807be1e20fcabd9e2c232ea01b64ce60f256e68749ed40a61db4392
> Blocks: 0 Seconds: 0
> contract address: 0x54A13cb54bD547f749a32959118cDb3E7c2b0Ee9
> block number: 31
> block timestamp: 1610569925
> account: 0x4f41f50211b97527a625BbE86D9Bed6AEBD85321
> balance: 99.77302744
> gas used: 186951 (0x2da47)
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.00373902 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.00373902 ETH
2_deploy_contracts.js
=====================
Replacing 'Token'
-----------------
> transaction hash: 0xa7104779b88389cc116e9c9492ee26b5a6824dda7505ebb3a4860476d374cfa6
> Blocks: 0 Seconds: 0
> contract address: 0xC30B06Df705b2B86ebF46E61F799Ee5B0d476229
> block number: 33
> block timestamp: 1610569926
> account: 0x4f41f50211b97527a625BbE86D9Bed6AEBD85321
> balance: 99.75454758
> gas used: 881658 (0xd73fa)
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.01763316 ETH
TypeError: Cannot read property 'bytecode' of undefined
at Deployer._preFlightCheck (/Users/tony/.nvm/versions/node/v12.13.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:173:1)
at /Users/tony/.nvm/versions/node/v12.13.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:282:1
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Truffle v5.1.58 (core: 5.1.58)
Node v12.13.0
I just got a similar error because I had
await deployer.deploy();
in my migration file. You must enter the contract argument
await deployer.deploy(MyToken);

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.

Setting gas for truffle

I'm running truffle migrate on main. Also using geth.
I originally left gas price and gas empty in truffle.js, but now it looks like this:
live: {
network_id: 1,
host: "127.0.0.1",
port: 8545,
from: "3984bc76cb775d7866d1cd55c4f49e3d13d411d4",
gas: 40000,
gasPrice: 22000000000 // Specified in Wei
}
I seem to have a situation where I either have too much gas or not enough, with no possibility for the right amount.
< {
< "jsonrpc": "2.0",
< "id": 2,
< "error": {
< "code": -32000,
< "message": "insufficient funds for gas * price + value"
< }
< }
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: insufficient funds for gas * price + value
...or...
< {
< "jsonrpc": "2.0",
< "id": 2,
< "error": {
< "code": -32000,
< "message": "exceeds block gas limit"
< }
< }
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: exceeds block gas limit
When I run web3.eth.getBlock("latest") in console, I get gasLimit: 5000. When I set my gas at 5000 I get the insufficient funds message. When I set it to 5001, I get "exceeds block gas limit".
So, all this seems to be telling me that the gasLimit should be set to 5000 or under 5000, but in that case I don't have sufficient funds to run the transaction. Let's see...
I have:
gas: 5000,
gasPrice: 22000000000 // Specified in Wei
5000 * 22000000000 = 1.1 * 10^14 = 110,000,000,000,000 Wei
1.1 * 10^14 / 10 ^ 18 (number of Wei in 1 Ether) = 1.1*10^-4 ETH
Here's the account I'm using: https://etherscan.io/address/0x3984bc76cb775d7866d1cd55c4f49e3d13d411d4. As you can see, it has funds. 0.01738465 Ether at time of writing, to be precise.
if you are on a test network, on testrpc, the option -l or --gasLimit lets you set the gas available.
On geth, this post should help : https://ethereum.stackexchange.com/questions/13730/how-to-increase-gas-limit-in-block-using-geth
This randomly started working the following day. One thing I noticed was that when I ran web3.eth.getBlock("latest") in truffle console yesterday, I was getting gasLimit: 5000, which was a way lower number than the network was reporting elsewhere. Today I was getting gasLimit: 6706583. I'm really not sure what caused the gas limit to increase locally, but whatever it was seems to have fixed the issue.
I also faced the similar issue. The version of truffle I was using was Truffle v4.0.1 (core: 4.0.1). If you downgrade to beta version things will work just fine.
npm uninstall -g truffle
truffle version(to check if its uninstalled)
npm install -g truffle#beta
You are good to go. This should fix the problem.
I was having the same issue and this is how I made it work:
In truffle console, find out the gas limit for the last block. Use that number in your truffle.js. In my case gas: 4700036 worked.
truffle(development)> web3.eth.getBlock('latest').gasLimit
4700036
To increase the gas limit in Truffle.
which truffle to get location of Truffle
Open in code editor.
code /home/user/.nvm/versions/node/v8.11.1/bin/truffle
currently the limit was set at 6721975so i just searched for this number
crtl+f 6721975 Change it to 8000000 or whatever.
now in truffle develop web3.eth.getBlock('latest') // 8000000

I can not put a contract on to ethereum via Remix-Solidity by error - Invalid sender

I tried to run the following contract on to the ethereum blockchain,though,
I got a error of "callback contain no result Error: Invalid sender".
pragma solidity ^0.4.0;
contract SingleNumRegister {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
The accounts[0] already has enough Gas and it is unlocked.
I have no idea of why this message occurs. Please give me some advice to solve the issue.
//////Data of environment///////
IDE :
Browser-Only Solidity IDE and Runtime Environment
remix-4a2c813.zip.
Web3 Provider
geth :
geth --datadir "/home/yuichi/ethe-prj/dprvnet" --port 30304 --networkid 1234 --rpc --rpcport "8545" --nodiscover --rpccorsdomain "*" console 2>./console.log
instance: Geth/v1.6.1-stable-021c3c28/linux-amd64/go1.8.1
coinbase: 0x91be0471171c5ddfe94cf5b3b81d1d1d5e9cab26
at block: 9466 (Fri, 02 Jun 2017 05:35:45 JST)
datadir: /home/yuichi/ethe-prj/dprvnet
modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
I found out the cause why this happened. genesis.json was incorrect.
Actually config section was wrong. I corrected like this:
"config": {
"chainID": 10,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
And I started again with "geth init" command again like:
geth --datadir AAA init genesis.json
And I created a node and started mining. The error was fixed!