0

I wanted to implement a public testnet on ethereum on python can anyone help me it must be proof of work as consensus method and currently i am learning hashing and how to implement proof of work but can anyone tell me in detail how transactions work full in documentation or in practical form ?

2
  • Why u want your own test net while u can use any one of the public test net
    – Majd TL
    Sep 24 at 19:23
  • Ethereum transactions are explained in detail in the Yellow Paper.
    – Ismael
    Sep 28 at 5:14
0

-install metamask extension on your browser.

-resister to https://infura.io/dashboard/ethereum and you can select the testnet(ropsten, kovan, rinkeby...) and check the project_id

-faucet free eth to your wallet to test transaction(aucet.rinkeby.io for rinkeby, https://faucet.ropsten.be/ for ropsten, https://enjin.io/software/kovan-faucet for kovan)

from web3 import Web3
Tx = require("ethereumjs-tx").Transaction
web3 = new web3('https://testnet.infura.io/v3/project_id')

//now we try to test network
account1 ='0x3d..'//from address
account2 = '0x2h..'//to address
private_Key_1 = 'privateKey'
privateKey1Buffer = Buffer.from(private_Key_1, 'hex')
//You can check the balance of wallets(from address, to address)
web3.eth.getBalance(account1, (err,bal) => { console.log('account 1 balance :' , web3.utils.fromWei(bal, 'ether'))})
web3.eth.getBalance(account2, (err,bal) => { console.log('account 2 balance :' , web3.utils.fromWei(bal, 'ether'))})
await web3.eth.getTransactionCount(account1, (err,txCount) => {
      txObject ={
            nonce: web3.utils.toHex(txCount),
            to: account2,
            value: web3.utils.toHex(web3.utils.toWei(''+amount, 'ether')),
            gasLimit: web3.utils.toHex(21000),
            gasPrice: web3.utils.toHex(web3.utils.toWei('10','gwei')),
        }
//2 sign transaction with my private key
tx = new Tx(txObject, { chain: 'mainnet' })
tx.sign(privateKey1Buffer)

serializedTransaction =tx.serialize()
raw ='0x'+serializedTransaction.toString('hex')

web3.eth.sendSignedTransaction(raw, (err,txHash) => {
            console.log('txHash : ',txHash)
            if (txHash === undefined) {
                web3.eth.getBalance(account1, (err,bal) => { alert('Your account has ' + web3.utils.fromWei(bal, 'ether') + ', So Please input less than ' + web3.utils.fromWei(bal, 'ether'))})
                handleSuccessFalse();
            }
            else
                handleSuccessTrue();
        })
    })
  //Finally, You can check transaction success through checking the changed balance of wallets.
  web3.eth.getBalance(account1, (err,bal) => { console.log('account 1 balance :' , web3.utils.fromWei(bal, 'ether'))})
  web3.eth.getBalance(account2, (err,bal) => { console.log('account 2 balance :' , web3.utils.fromWei(bal, 'ether'))})
}

I would be happy if this could help you.

Thanks.

1
  • no i was looking for creating a full blockchain or you can say hard forking the ethereum Blockchain can you help me in that ? Sep 25 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.