Exceeds block gas limit while deploying the contract in latest ethereum - ethereum

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"
}
}

Related

CodeBuild succeeds while Node build command has failed

Let's assume that we have AWS CodeBuild project which buildspec file contains the following:
"phases": {
"install": {
"runtime-versions": {
"nodejs": 14
}
},
"build": {
"commands": [
"echo Build started on `date`",
"npm ci && npm audit --audit-level=critical",
"node -r esm index.js --env=CLOUDTEST"
]
},
"post_build": {
"commands": [
"echo Build completed on `date`"
]
}
It runs successfully, but if, for example, env value is wrong, node command will fail, but the build still succeeds.
Question: what should I do to make CodeBuild project to fail when node command fails?
The build phase transitions to post_build by default, regardless whether the build succeeds or fails. To override this behaviour, explicitly set the phase's on-failure behaviour:
"build": {
"on-failure": "ABORT",
"commands": ["node BOOM"]
},
The bad node BOOM command causes the execution to fail immediately. Logs tail:
[Container] 2022/04/29 11:21:10 Command did not exit successfully node BOOM exit status 1
[Container] 2022/04/29 11:21:10 Phase complete: BUILD State: FAILED_WITH_ABORT
[Container] 2022/04/29 11:21:10 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: node BOOM. Reason: exit status 1

Ethereum private testnet failing due to peers not connecting

The problem
I want to create a private Ethereum network, however my two peers refuse to connect. They always fail with the following error: Snapshot extension registration failed peer=af5dfeb7 err="peer connected on snap without compatible eth support".
My attempted fixes
Setting --snapshot=false produces the same error
Changing the --syncmode to full, fast or light made no difference
Adding the peers manually with admin.addPeer(${peer1.admin.nodeInfo.enode}) returns true, however net.peerCount and admin.peers.length return 0
Changing the chainId did not produce any different results
Waiting did not help
My setup proccess
Creating the peers:
geth init --datadir "peer1" genesis.json
geth init --datadir "peer2" genesis.json
Starting the peers and opening the console:
geth --datadir "peer1" --networkid 1111 --port 30401 console 2>peer1.log
geth --datadir "peer2" --networkid 1111 --port 30402 console 2>peer2.log
The genesis file (Created by puppeth)
{
"config": {
"chainId": 1111,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x61af5dd9",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": null
}
Geth version info
Geth
Version: 1.10.13-stable
Git Commit: 7a0c19f813e285516f4b525305fd73b625d2dec8
Architecture: amd64
Go Version: go1.17.2
Operating System: linux
GOPATH=
GOROOT=go

geth event newPendingTransactions does not occur

I've got running geth with next command:
$ geth --testnet --networkid 3 --verbosity 3 --syncmode light --ipcdisable --ws --wsapi "db,eth,net,web3,personal,txpool,admin,miner" --wsorigins '*'
In second console I connect to geth jsonrpc with wscat.
Subscribing to an event "newHeads" works fine:
$ wscat -c ws://localhost:8546
> {"id": 2, "method": "eth_subscribe", "params": ["newHeads"]}
< {"jsonrpc":"2.0","id":2,"result":"0x660135584e36a9edb0c55f89c389848"}
< {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x660135584e36a9edb0c55f89c389848","result":{"parentHash":"0xe7d0...","hash":"0x1dcc...
But subscribing to an event "newPendingTransactions" not works:
$ wscat -c ws://localhost:8546
> {"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}
< {"jsonrpc":"2.0","id":1,"result":"0x511b3274aa5dec44bb79d178c238e7fe"}
And it's all: I do not get new pending transactions.
Subscribing to an event "newPendingTransactions" on ropsten.infura.io works fine:
$ wscat -c wss://ropsten.infura.io/ws
> {"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}
< {"jsonrpc":"2.0","id":1,"result":"0x18fda7bf20ee9c5b5f1f08edf5c3e482"}
< {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x18fda7bf20ee9c5b5f1f08edf5c3e482","result":"0xc1e00266ab9f2c512d6c1967c300fc00381586e868611b7dff6fd94f230dd707"}}
Info:
$ geth version
Geth
Version: 1.8.22-stable
Git Commit: 7fa3509e2eaf1a4ebc12344590e5699406690f15
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.4
Operating System: linux
GOPATH=
GOROOT=/usr/lib/go-1.10
I have two questions:
1. Why subscribing to event "newPendingTransactions" not works?
2. What am I doing wrong?
The problem was that I did not wait for the end of synchronization.
I started from scratch (this time i used Rinkeby network):
geth --rinkeby --verbosity 3 --syncmode fast --ipcdisable --ws --wsapi "db,eth,net,web3,personal,txpool,admin" --wsorigins '*'
For the Rinkeby network, this took about 20 hours and the size of the blockchain is about 25 gigabytes on my SSD.
And now the subscribing for newPendingTransactions event works fine!
Thanks all!

geth shows "contract creation code storage out of gas" when I deploy contract from remix

I created a private network using geth.
And deploy a contract from remix (browser).
It shows following error.
genesis.json is this.
{
"config": {
"homesteadBlock": 0
},
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x4000",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"alloc": {}
}
And I created 2 accounts and run network by this code.
geth --identity "sampleNode" --rpc --rpcport 8545 --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --rpcaddr "0.0.0.0" --datadir "~/eth-private-net/" --nodiscover --networkid 10 --unlock 0,1 --verbosity 6
And I deployed the contract.
pragma solidity ^0.5.0;
contract SingleNumRegister {
uint storedData;
function set(uint x) public{
storedData = x;
}
function get() public view returns (uint retVal){
return storedData;
}
}
After that, it shows error on geth console log.
DEBUG[01-27|11:05:50.009] VM returned with error err="contract creation code storage out of gas"
I got eth by mining and the account has 315 ether on my private network, but it shows same error.
> eth.getBalance(eth.accounts[0]);
315000000000000000000
What is the problem?
If you deploy using remix there is a field called gas limit. If your gas limit is 3000000 it should be enough, when I deploy your contract on remix it costs much less than that.
Also since you said you deploy on a private blockchain it could have something to do with the gas cost there. Try to deploy in the remix JavascriptVM to see if it works (this works in my case). If it works there try increasing the gas limit when deploying on your private blockchain.

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!