hide You are viewing an archived web page, collected at the request of Ethereum Foundation using Archive-It. This page was captured on 10:29:25 Jun 22, 2021 , and is part of the Community collection. The information on this web page may be out of date. See All versions of this archived page. Loading media information

How does a batch of deployed contracts know which one to default to when funding?

How does a batch of deployed contracts know which one to default to when funding it with money?

I know that one can write multiple contracts within the same batch that will be deployed.
for example:
contract System1 { ... }
contract System2 { ... }
These contracts are deployed together. So how do I state which one is the main contract to start from?

What I want to do is make a hodl souvenir contract. When you put in ETH to for the contract to hold, you get a hodl-token.
So what I'd need is one contract called the hodlr with an address mapping of hodl's, and then another contract for the address mapping of the hodl bonus token.

I know I can create a contract from another contract. For instance
contract Factory {
    address[] newContracts;

    function createContract (bytes32 name) {
        address newContract = new Contract(name);

contract Contract {
    bytes32 public Name;

    function Contract (bytes32 name) {
        Name = name;
But how do I know which one the default "Fund" function will go to? Can both contracts have that default function? Or just one?
It would seem like the "Contract" contract would be accessible like the "Factory" contract is. But the "Factory" can create instances of "Contract". Are contracts an instance and a class? Is that what's going on?


  • o0ragman0oo0ragman0o Member, Moderator Posts: 1,291 mod
    You can only deploy one contract per TX. In the case of your Factory, it compiles Contract bytecode within itself. A Contract instance is only deployed as a separate contract after calling createContract and using the embeded bytecode as input data.

    I'm not sure I follow you bonus tokens contract requirement from the description.
  • SixophreniaSixophrenia Member Posts: 7
    edited February 2018
    So is Factory the primary contract? is it the only deployed contract? Is it because it's first?

    The bonus token idea can be seen here in my first contract.

    There is only 1 contract, but it has two mappings. One to keep track of your "place" within the contract, another for a reward token.
    Because I fused together the ERC20 token contract into this other contract, I accidently removed one of the contracts "totalSupply()" functions.
    So I'm just trying to separate the contracts, and I need to know which one creates the seondary contract.

    You've answered enough, just about. The bonus token thing I feel I have covered.
    I just need to know why is factory the one deployed, when both are in the same .sol file?
  • o0ragman0oo0ragman0o Member, Moderator Posts: 1,291 mod
    How are you deploying? Normally you deploy per contract not per source file so the Factory is the only one you need to deploy. Personally I just use Remix to deploy and aren't so sure about what other frames (e.g. Truffle) do.
  • SixophreniaSixophrenia Member Posts: 7
    edited February 2018
    I feel like a fool, you're right. In the drop down it shows both.
Sign In or Register to comment.