5

I created a private blockchain console with an unlocked account.

I have a simple contract, simpleContract.sol

pragma solidity ^0.4.0;

contract SimpleStorage {
  uint storedData;

  function set(uint x) {
    storedData = x;
  }

  function get() constant returns (uint) {
    return storedData;
  }
}

It was made into a js file using

echo "var simpleOutput=`solc --optimize --combined-json abi,bin,interface simpleContract.sol`" > simpleStorage.js

I load my contract in the console using

loadScript("simpleStorage.js")
var simpleStorageContract = eth.contract(JSON.parse(simpleOutput.contracts["simpleContract.sol:SimpleStorage"].abi));
var simpleStorage = simpleStorageContract.new(   {     from: eth.accounts[0],      data: "0x" + simpleOutput.contracts["simpleContract.sol:SimpleStorage"].bin,      gas: '47000'   },  function (e, contract) { if(!e) {    if(!contract.address) {      console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");    } else {      console.log("Contract mined! Address: " + contract.address);      console.log(contract);    }  }})

I see

Contract transaction send: TransactionHash: 0x0f01f04f0e266cdca62479413bf17d65d38ef0b497dcbe9e9232451c994892a0 waiting to be mined...

When I start the miner with

miner.setEtherbase(eth.accounts[0])
miner.start(4)

It prints

INFO [07-01|18:22:03] Updated mining threads threads=4

INFO [07-01|18:22:03] Transaction pool price threshold updated price=18000000000

INFO [07-01|18:22:03] Starting mining operation

INFO [07-01|18:22:03] Commit new mining work number=3062 txs=0 uncles=0 elapsed=309.753µs

INFO [07-01|18:22:06] Successfully sealed new block number=1 hash=a73c27…d68bae

INFO [07-01|18:22:06] 🔨 mined potential block number=2 hash=a73c27…d68bae

INFO [07-01|18:22:06] Commit new mining work number=3 txs=0 uncles=0 elapsed=126.412µs

INFO [07-01|18:22:08] Successfully sealed new block number=4 hash=577497…34db4e

How can I find when my contract will be mined? I was under the impression that I could find the block number using

eth.getTransaction

Any solutions?

3 Answers 3

3

use the command web3.eth.getTransaction(transactionHash [, callback]) This will return in what block your transaction was mined or null if it's still pending.

https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransaction

If get Transaction return 'null' it mean the transactionHash is not mined. You can check local pending transactions with "eth.pendingTransactions"

2
  • I tried web3.eth.getTransaction("0x0f01f04f0e266cdca62479413bf17d65d38ef0b497dcbe9e9232451c994892a0") it returned null Jul 2, 2017 at 13:06
  • I ran the miner for over a few hours, I must be doing something wrong. Any suggestions? Jul 2, 2017 at 13:24
0

You can use getTransactionReceipt to check if a transaction was mined.

3
  • I tried web3.eth.getTransactionReceipt("0x0f01f04f0e266cdca62479413bf17d65d38ef0b497dcbe9e9232451c994892a0") and get null. How much time does it take for it to be mined? Jul 2, 2017 at 13:09
  • Are blocks being generated? Check with web3.eth.blockNumber. A block should generated each 15 seconds. If no blocks are generated then your difficulty is set too high in genesis.json. Lower it and reset your private blockchain.
    – Ismael
    Jul 2, 2017 at 23:04
  • 1
    I found the way around it. I increased the ether amounts and it went through. I wish it was simpler. Jul 5, 2017 at 21:01
0

I wrote a tutorial doing the same thing as you did.
https://medium.com/@tina26919742/a-complete-guide-on-building-a-smart-contract-on-a-private-net-in-ethereum-726851c7c044
But I see the contract is mined soon after miner.start (just a few seconds)
Can you provide more details on how you set up your private blockchain?

You can also append else console.log(e) to your callback function to see what happened.

2
  • I read your tutorial. It is outdated in one place. You have included the compiler inside the console, web3.eth.getCompilers() does not exist anymore. You have to compile outside and bring in the bin and abi files now. Jul 5, 2017 at 20:59
  • yeah so I used geth version 1.5.9 instead of the latest, which still has the compiler. I do that because I think it may be better for beginners to follow. Maybe I should also include that in my tutorial. Thanks for the advice!
    – Tina Lee
    Jul 5, 2017 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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