How can I send transaction with no gas fee on private chain - ethereum

I want to send transaction with no gas fee.
I made a private chain which and started geth with gas price is 0 like below.
geth --datadir node1/ --syncmode 'full' --port 30311 --rpc --rpcaddr '0.0.0.0' --rpcport 8545 --rpccorsdomain "*" --rpcvhosts "*" --rpcapi 'personal,db,eth,net,web3,txpool,miner' --networkid 1515 --gasprice '0'
However, it is not supposed to need gas fee, but error message shows that intrinsic gas too low.
My code in like below
const customCommon = Common.forCustomChain(
'mainnet',
{
name: 'privatechain',
networkId: 1515,
chainId: 1515,
},
'petersburg',
)
const functionAbi = await this.state.contract.methods.setGreeting(this.state.text).encodeABI()
console.log(this.state.nonce)
var details = await {
nonce : this.state.nonce,
gasPrice : 0,
gas : 0,
gasLimit: 0,
from : this.state.web3.eth.coinbase,
to: this.state.address,
value : 0,
data : functionAbi,
};
const transaction = await new EthereumTx(details, { common: customCommon },);
await transaction.sign(this.state.pk)
var rawdata = await '0x' + transaction.serialize().toString('hex');
console.log(rawdata)
await this.state.web3.eth.sendSignedTransaction(rawdata)
.on('transactionHash', function(hash){
console.log(['transferToStaging Trx Hash:' + hash]);
})
.on('receipt', function(receipt){
console.log(['transferToStaging Receipt:', receipt]);
})
.on('error', console.error);
Are there any problem of my code? Could give me any advise, please?

The transaction can't be included in a block when there is no block available. You have to activate mining so blocks can be mined and your sent transaction can be included.
You have to add --mine --mine.threads 1
This will activate mining and create 1 thread to mine for new blocks.
Also --unlock must be used to unlock your account (in this case account 0, which is the coinbase).
In order to successfully unlock your account, you have to provide the password of account 0 in a .sec file. The file contains only the password without any spaces or new lines.
After you have created the file add the following:
--password <path of the .sec file>
If you are working on your private chain add --allow-insecure-unlock, because otherwise the unlock won't work. You can look up the reason in another post if you want.
So all in all you should add the following:
--mine --miner.threads 1 --unlock --allow-insecure-unlock --password <path of the .sec file>
The option "gasprice" is marked as deprecated when looking at "geth help".
You should use --miner.gasprice '0'.

Related

Unable to deploy an ERC 720 token in Mumbai Test says insufficient funds

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

INFURA: sender account not recognized

I am trying to deploy my contract but it returns this error
truffle migrate --network ropsten --reset
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
Error: Error: Error: *** Deployment Failed ***
"Migrations" -- sender account not recognized.
truffle_config.js
ropsten: {
provider: function() {
return new HDWalletProvider(mnemonic, "https://ropsten.infura.io/v3/<PROJECTID>")
},
network_id: "*",
gas: 4000000,
from: "0x4e2f89...."
}
By default, the HDWalletProvider will use the address of the first
address that's generated from the mnemonic. If you pass in a specific
index, it'll use that address instead.
So if you are using address that isn't the first address from this mnemonic you should ether specify the address
HDWalletProvider(mnemonic, "ropsten.infura.io/v3/<PROJECTID>", indexOfYourAddress)
or unlock multiple addresses by putting number to the forth parameter
HDWalletProvider(mnemonic, "ropsten.infura.io/v3/<PROJECTID>",0, numberOfAddresses)

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

Unable to run truffle#2.1.2 migrate --network live. "Exceeds block gas limit"

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

Create entity in a service using IDAS and ContextBroker

So I'm having some problems connection virtual devices to the contextBroker and i thing it's because of the Fiware-Service. I don't want to use the OpenIoT (even though that didn't worked for me either). I didn't manage to find any documentation about service creation and maybe i'm creating it wrong.
I did Python CreateService bus_auto 4jggokgpepnvsb2uv4s40d59ovand i'm not sure it returns me 201. I updated the config.ini file to work on MY service but when i send the observations it doesn't change the value of the entity on the contextBroker
I'm now running it in
My config.ini file:
[user]
# Please, configure here your username at FIWARE Cloud and a valid Oauth2.0 TOKEN for your user (you can use get_token.py to obtain a valid TOKEN).
username=
token=NULL
[contextbroker]
host=127.0.0.1
port=1026
OAuth=no
# Here you need to specify the ContextBroker database you are querying.
# Leave it blank if you want the general database or the IDAS service if you are looking for IoT devices connected by you.
fiware_service=bus_auto
[idas]
host=130.206.80.40
adminport=5371
ul20port=5371
OAuth=no
# Here you need to configure the IDAS service your devices will be sending data to.
# By default the OpenIoT service is provided.
fiware-service=bus_auto
fiware-service-path=/
apikey=4jggokgpepnvsb2uv4s40d59ov
[local]
#Choose here your System type. Examples: RaspberryPI, MACOSX, Linux, ...
host_type=CentOS
# Here please add a unique identifier for you. Suggestion: the 3 lower hexa bytes of your Ethernet MAC. E.g. 79:ed:af
# Also you may use your e-mail address.
host_id=db:00:ff
I'm using the python script GetEntity.py:
python2.7 GetEntity.py bus_auto_2
I also tried using a python script that i created:
import json
import urllib
import urllib2
BASE_URL = 'http://127.0.0.1:1026'
QUERY_URL = BASE_URL+'/v1/queryContext'
HEADERS = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
QUERY_EXAMPLE = {
"entities": [
{
"type": "bus_auto_2",
"isPattern": "false",
"id": "Room1"
}
]
}
def post(url, data):
""""""
req = urllib2.Request(url, data, HEADERS)
f = urllib2.urlopen(req)
result = json.loads(f.read())
f.close()
return result
if __name__ == "__main__":
print post(UPDATE_URL, json.dumps(UPDATE_EXAMPLE))
print post(QUERY_URL, json.dumps(QUERY_EXAMPLE))
I see the service is well created and actually I see one device defined within it.
I have even successfully sent an observation (t|23) bus_auto_2 device
Later, I check in the ContextBroker this entity: "thing:bus_auto_2" and I see the latest observation I sent.
Did you update in the config.ini file the FIWARE_SERVICE both at ContextBroker and IDAS sections ?
Cheers,
Looking to your script, it seems you are not including the Fiware-Service header in you queryContext request. Thus, the query is resolved in the "default service" and not in bus_auto service.
Probably changing the HEADERS map in the following way would solve the issue:
HEADERS = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Fiware-Service: 'bus_auto'
}
EDIT: In addition to the above change, note that the BASE_URL is pointint to a local Orion instance, not the one connected with IDAS (which run in the same machine that IDAS). Thus, I think you also need to modify BASE_URL in the following way:
BASE_URL = 'http://130.206.80.40:1026'