I'm building a Dapp where, whenever a user creates an account, a contract is immediately created from his account. However, I need a way to quickly find the contract's address in the future.

The alternative I've been using is just to have a mongoDB storage per user, updating the contractAddress field there whenever the contract is mined. Ideally though, I'd like to avoid centralised storage. Is there a way to do this?

  • Will finding the contracts address while deploying the contract instead of waiting for mining, solve your problem.
    – joifsi
    Jul 28 '17 at 13:16
  • I can already find the contract's address when I deploy it. The thing is, if I want to fetch the contract's address in my Dapp every time I need to show if to a user, I'd need a fast method to get the first transaction from the user's account. Does that make sense?
    – mcansado
    Jul 28 '17 at 13:21
  • I do not think there is any fast way to get the transactions made by an account. This feature was discussed at length here github.com/ethereum/go-ethereum/issues/1897
    – joifsi
    Jul 28 '17 at 13:32

I'm not sure this is exactly what you meant.

Here, the user can ask the Hub to deploy a new Stub. The user gets ownership of the new Stub and the Hub tracks contracts owned by each user.

Sketched out quickly. No warranty ;-)

pragma solidity 0.4.19;

contract Owned {

    address public owner;

    function Owned() public {
        owner = msg.sender;

    function changeOwner(address newOwner) public returns(bool success) {
        require(msg.sender == owner);
        owner = newOwner;
        return true;

contract HubInterface {
    function deployStub() public returns(address newStub);
    function isHub() public pure returns(bool isIndeed);
    function getUserContractAtRow(address user, uint row) public view returns(address userContract);

contract Stub is Owned{

    address public owner;
    HubInterface hub;

    function Stub() public {
        hub = HubInterface(msg.sender);

contract Hub is HubInterface, Owned {

    mapping(address => address[]) userContracts;

    function deployStub() public returns(address newStub) {
        Stub s = new Stub();
        return address(s);

    function isHub() public pure returns(bool isIndeed) {
        return true;

    function getUserContractAtRow(address user, uint row) public view returns(address userContract) {
        return userContracts[user][row];

Hope it helps.


There is no fast way to do this as you would have to look through the transactions of every block to discern which transactions were sent from a particular address.

This can be done using the Parity trace module for example.


QuickBlocks, which we are about to release, can do this. Otherwise, if we want to start 'monitoring' a new address, we have to start at the beginning of the chain every time and scan forward. We've written code that stores 'first encountered block' per contract, but it's not industrial scale. Basically we do this using Parity's trace module and cache the results so you don't have to re-do that every time you want information.


The address of a contract is fully deterministic. You can calculate the address in advance, as it's basically an operation based on the the contract-factory's address (the user) and the nonce of the contract-factory's address.

You can use for example ethereumjs-util to calculate this address in advance.

> eth.generateAddress('990ccf8a0de58091c028d6ff76bb235ee67c1c39',14).toString('hex')

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.