Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure transactions take 0 fee in a private Ethereum blockchain?

I have a private parity node setup on my laptop. How can I make sure that there is 0 transaction fee whenever a transaction is posted in this private ethereum blockchain, meaning that I can post a transaction giving "gas: 0"?

Example: Account A has 20 ether, Account B has 0 ether. When I transfer 10 ether from Account A to Account B, Account A now shows 9.980 and Account B shows 10.

How can I prevent the extra gas being deducted?

Any help is appreciated.

like image 799
Suraj Kohli Avatar asked Mar 16 '18 10:03

Suraj Kohli


1 Answers

You control the miners in the private network, so you just need to customize them to accept transactions with gasPrice = 0.

From the Parity documentation:

--gasprice WEI                   Minimum amount of Wei per GAS to be paid for a
                                 transaction to be accepted for mining. Overrides
                                 --basic-tx-usd.

Note that this doesn't change how gas itself works in the network. You still have gas limits and can generate out of gas errors. The only difference is that the client is saying it will pay 0 for gas on a transaction and the miner is staying it is willing to accept transactions at 0 price.

EDIT - To address comments:

Admittedly, I use Geth over Parity, but this works in Geth and I'd be surprised if it was once supported in Parity and then disabled. You may have to change the Parity source code to get it to work. Alternatively, you can switch to Geth.

Showing the results in Geth below

Terminal 1

$ geth --networkid 29462 --datadir "./data" --gasprice 0 --nodiscover --port 31313

<Output Truncated>

Terminal 2

$ geth attach '//./pipe/geth.ipc'
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.2-stable-b8b9f7f4/windows-amd64/go1.9.2
coinbase: 0xd69cc234de15189f0ba998a41421961e89837fc5
at block: 79 (Tue, 06 Mar 2018 07:56:30 PST)
 datadir: C:\cygwin\home\adamk\eth\private\node1\data
 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

> web3.eth.getBalance('0x1b8c05505f86bf20c6a1110073cd6f9b3bf555df');

2000000000000000000

> web3.eth.sendTransaction({to: '0xd69cc234de15189f0ba998a41421961e89837fc5', from: '0x1b8c05505f86bf20c6a1110073cd6f9b3bf555df', gasLimit: 6000000, gasPrice: 0, value: web3.toWei(1, 'ether')});

"0x1eceea33aee0bd27feccd1d7aba371459090bb60af2cc18d63548112019ac2b9"

> web3.eth.getBalance('0x1b8c05505f86bf20c6a1110073cd6f9b3bf555df');

1000000000000000000

> web3.eth.getTransaction('0x1eceea33aee0bd27feccd1d7aba371459090bb60af2cc18d63548112019ac2b9');

{
  blockHash: "0xad40ce3bfa30b2551dbd085c29ac1800add8b9bc464944625b82fb17df567823",
  blockNumber: 897,
  from: "0x1b8c05505f86bf20c6a1110073cd6f9b3bf555df",
  gas: 90000,
  gasPrice: 0,
  hash: "0x1eceea33aee0bd27feccd1d7aba371459090bb60af2cc18d63548112019ac2b9",
  input: "0x",
  nonce: 0,
  r: "0xc55b5a25f4c7670418f304db44d949f5a077c1b4c8cfcc89b486a84cccb59d22",
  s: "0x7d1d5ee1ed54a0098299d44bd692fc0d3d249609b3c01810beb00180d11e2e35",
  to: "0xd69cc234de15189f0ba998a41421961e89837fc5",
  transactionIndex: 0,
  v: "0x1b",
  value: 1000000000000000000
}

(Note that the initiator of the transfer, 0x1b8c05505f86bf20c6a1110073cd6f9b3bf555df, was decremented by exactly 1 ether. No fees paid.)

like image 177
Adam Kipnis Avatar answered Sep 19 '22 12:09

Adam Kipnis