Pretty much as stated in the title, after running truffle test I get this:
TestMetacoin
1) "before all" hook: prepare suite
Contract: MetaCoin
✓ should put 10000 MetaCoin in the first account
2) should call a function that depends on a linked library
> No events were emitted
✓ should send coin correctly (6078ms)
2 passing (6s)
2 failing
1) TestMetacoin "before all" hook: prepare suite:
Error: Intrinsic gas too low
at Object.InvalidResponse (/usr/lib/node_modules/truffle/node_modules/truffle-contract/node_modules/web3/lib/web3/errors.js:35:16)
at /usr/lib/node_modules/truffle/node_modules/truffle-contract/node_modules/web3/lib/web3/requestmanager.js:86:36
at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:119:13)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/usr/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:469:24)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
2) Contract: MetaCoin should call a function that depends on a linked library:
AssertionError: Library function returned unexpected function, linkage may be broken: expected 0 to equal 20000
at test/metacoin.js:25:14
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
My genesis block is as follows:
{
"nonce": "0x0000000000000042",
"difficulty": "0x4000",
"alloc": {
"0xfd0ceb7965a0e4c3146c1f901fbab9668653af6b": {
"balance": "325406000000000"
}
},
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0xfd0ceb7965a0e4c3146c1f901fbab9668653af6b",
"etherbase" : "0xfd0ceb7965a0e4c3146c1f901fbab9668653af6b",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x3d0900"
}
And my truffle.js is like this:
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*", // Match any network id
gas: 1000000
}
}
};
I fail to understand what is wrong with gas at these settings. Even if noone has the exact answer, some additional explanation of the gas limits (not the gas itself) would be helpful.
I ended up changing genesis block gasLimit to
"gasLimit": "0x2FEFD800",
config for homestead block to 10 (apparently otherwise there are issues when working with geth):
"config": {
"homesteadBlock": 10
},
and truffle.js gas setting to 5000000.
Tests pass.
Related
I was trying to deploy an ERC 721 token using truffle in Polygon's mumbai testnet.
And i have 2.8296 Matic in my metasmask wallet which i got from their faucet. But when i try to run
truffle migrate --network matic
it says
Error: *** Deployment Failed ***
"Migrations" could not deploy due to insufficient funds
* Account: 0x12aADAdd301d22c941DACF2cfa7A9e2019972F61
* Balance: 0 wei
* Message: insufficient funds for gas * price + value
* Try:
+ Using an adequately funded account
+ If you are using a local Geth node, verify that your node is synced.
Am i doing something wrong? What sould be the gas and gas price i should mention in truffle config file.
Here is my truffle-config file
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
matic: {
provider: () => new HDWalletProvider(process.env.MNEMONIC, `https://rpc-mumbai.maticvigil.com/v1/91fdbb5c2f37c699621ss7d2b8b127fc1a123060
`),
network_id: 80001,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
enter image description here
I am pretty sure there is no balance of this account 0x12aADAdd301d22c941DACF2cfa7A9e2019972F61 in Mumbai-Testnet
I am trying to execute the steps from https://medium.com/#mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2.
However, the difference is I am running geth on AWS server instead of truffle or testnet as specified in the link. I need to get deployed contract address to try on UI. I am using the following geth command: geth --networkid 12312423 --port 30303 -rpc -rpcaddr "0.0.0.0" -rpcport 8080 --rpcapi "web3,db,net,personal,eth" --rpccorsdomain "*" --preload mining.js --nodiscover --maxpeers 0 --datadir=~/eth/data231 init genesis.json console
I have run Node commands on another screen in the same machine. I have gone till the end of the steps and I am receiving Error: exceeds block gas limit while deploying the contract. Is there any error in the genesis.json that I am using.
Any suggestions will help thanks...
genesis.json
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "200000000",
"gasLimit": "2100000",
"alloc": {
"7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
"f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
}
}
The problem is solved. There are 2 learnings from the solution:
The gasLimit in the genesis.json should be higher like "gasLimit": "3141592000000".
We should first start geth without init. Create account, unlock. Then allocate the balance for the account as below and do git init.
i.e.
Once you’ve generated your account, quit geth with and remove every folder except keystore/ from your datatir:
$ cd
$ rm -rf ls | grep -v keystore
update your genesis block json, adding the following to the alloc key:
"alloc": {
"": {
"balance": "10000000000000000000"
}
}
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!
I am using truffle#2.1.2 to deploy smart contracts against a localhost:8545 geth#1.5.9-stable rpc, using an account that is funded with Ether has been unlocked using personal.unlockAccount on the geth console.
I have also tried the same against a remote Parity node via RPC, but this is the latest which I am rather stuck with.
truffle.js
module.exports = {
build: {
"index.html": "index.html",
"app.js": [
"javascripts/app.js"
],
"app.css": [
"stylesheets/app.css"
],
"images/": "images/"
},
rpc: {
host: "localhost",
port: 8545
},
networks: {
"ropsten": {
network_id: 3,
port: 8548, // ssh tunnelled to AWS geth/parity node localhost:8545
from: "0x4f000Bcf4641E2fDcE85BF26A694b053996850D4"
},
"live": {
network_id: 1,
port: 8545,
from: "0x00269400181f1B379784BD8cDF786bb20e91Bdef",
gas: 4612388,
gasPrice: 2776297000 // taken from Parity startup log message "Updated conversion rate to Ξ1 = US$42.88 (2776297000 wei/gas)"
}
}
};
truffle migrate --network live
Running migration: 1_initial_migration.js
Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Exceeds block gas limit
at Object.module.exports.InvalidResponse (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/ether-pudding/node_modules/web3/lib/web3/errors.js:35:16)
at /home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/ether-pudding/node_modules/web3/lib/web3/requestmanager.js:86:36
at request.onreadystatechange (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:114:13)
at dispatchEvent (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
at setState (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:610:14)
at IncomingMessage.<anonymous> (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
I have tried adjusting gas and gasPrice, but am unable to find values that have any affect.
How can I solve this problem, or are there alternative contract deployment methods I should look into?
Kind Regards.
I was able to solve this by simply setting gas: 3000000 in the network config.
"live": {
network_id: 1,
port: 8545,
from: "0x00269400181f1B379784BD8cDF786bb20e91Bdef",
gas: 3000000
}
It cost about 0.5 ETH to run migrations and took several minutes.
In my case the problem was generated by a user's empty balance.
so check your balances using the following function :
function checkAllBalances() {
var totalBal = 0;
for (var acctNum in eth.accounts) {
var acct = eth.accounts[acctNum];
var acctBal = web3.fromWei(eth.getBalance(acct), "ether");
totalBal += parseFloat(acctBal);
console.log(" eth.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " ether");
}
console.log(" Total balance: " + totalBal + " ether");
};
checkAllBalances();
if the balance is 0 mine some blocks or edit your genesis file.
I solve the same problem by indicate the network id when calling truffle,as:
truffle migrate --network live
and you should modify "from" tag in truffle.js with your unlocked account.
Simple solution: : add gas: 500000 ,(don`t forget to add comma at the last) in truffle.js
module.exports = {
networks: {
development: {
host: "localhost",
port: 8001,
network_id: 1234, // Match any network id
gas: 500000
}
}
};
I am trying to create a private network so that I can start testing my Solidity code. However, when starting the a geth private network with geth --rpc but I then run into an error for an invalid response. {"jsonrpc":"2.0","error":{"code":-32600,"message":"EOF"}} when checking localhost:8545.
I don't think it matters, but my genesis.json file is
{
"nonce": "0x0000000000000042", "timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0", "gasLimit": "0x8000000", "difficulty": "0x400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333", "alloc": { }}
I have also tried creating a test network with testrpc with just the command testrpc but here the localhost:8545 returns a parsing error {"jsonrpc": "2.0", "id": null, "error": {"message": "Parse error", "code": -32700}}.
What is the JSON that I am sending because it seems to be incorrectly written?
Thanks
It's hard to tell what exactly you are trying, but the JSON RPC endpoint of geth requires a JSON command, for instance try to query the web3 version with the following request:
{
"method": "web3_clientVersion",
"params": []
}
It complains because you do not provide any request, i.e., running a plain testrpc command.
But inbetween the lines I read that you are testing your solidity code. Have you had a look at the wonderful browser solidity?