Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Add address of deployed contract inside generated class #89

Closed
Stradivario opened this issue Sep 12, 2018 · 3 comments
Closed

Comments

@Stradivario
Copy link

Stradivario commented Sep 12, 2018

@krzkaczor Hello there and again thank you for the great tool! Many thanks!

I am having the following case:

import { Module, ModuleWithServices } from '@gapi/core';
import { Web3Token } from '@gapi/ethereum';
import { Coin } from '../core/contracts/Coin';
import { CoinCrowdsale } from '../core/contracts/CoinCrowdsale';

const CoinCrowdsaleABI = require('../../../truffle-metacoin-example/build/contracts/CoinCrowdsale.json');
const CoinABI = require('../../../truffle-metacoin-example/build/contracts/Coin.json');

@Module()
export class ContractsModule {
    public static forRoot(): ModuleWithServices {
        return {
            module: ContractsModule,
            services: [
                {
                    provide: Coin,
                    deps: [Web3Token],
                    lazy: true,
                    useFactory: async (web3: Web3Token) => {
                        return await Coin.createAndValidate(web3, CoinABI.networks[Object.keys(CoinABI.networks)[0]].address);
                    }
                },
                {
                    provide: CoinCrowdsale,
                    deps: [Web3Token],
                    lazy: true,
                    useFactory: async (web3: Web3Token) => {
                        return await CoinCrowdsale.createAndValidate(web3, CoinCrowdsaleABI.networks[Object.keys(CoinCrowdsaleABI.networks)[0]].address);
                    }
                }
            ]
        };
    }
}

Is there any way to make it like that ?

import { Module, ModuleWithServices } from '@gapi/core';
import { Web3Token } from '@gapi/ethereum';
import { Coin } from '../core/contracts/Coin';
import { CoinCrowdsale } from '../core/contracts/CoinCrowdsale';

@Module()
export class ContractsModule {
    public static forRoot(): ModuleWithServices {
        return {
            module: ContractsModule,
            services: [
                {
                    provide: Coin,
                    deps: [Web3Token],
                    lazy: true,
                    useFactory: async (web3: Web3Token) => {
                        return await Coin.createAndValidate(web3, Coin.address);
                    }
                },
                {
                    provide: CoinCrowdsale,
                    deps: [Web3Token],
                    lazy: true,
                    useFactory: async (web3: Web3Token) => {
                        return await CoinCrowdsale.createAndValidate(web3, CoinCrowdsale.address);
                    }
                }
            ]
        };
    }
}

My current proposal is just to add deployed contract address when generating contract so it can be useful.Or is there any other way to obtain the address of the deployed contract ?

Regards,
Kristiyan Tachev

@Stradivario Stradivario changed the title Add address of deployed contract inside generated class [Proposal] Add address of deployed contract inside generated class Sep 12, 2018
@Stradivario
Copy link
Author

Stradivario commented Sep 12, 2018

Look at thaattt :(

const CoinCrowdsaleABI = require('../../../truffle-metacoin-example/build/contracts/CoinCrowdsale.json');
const CoinABI = require('../../../truffle-metacoin-example/build/contracts/Coin.json');

Obtaining the address is also a lot of code:

CoinCrowdsaleABI.networks[Object.keys(CoinCrowdsaleABI.networks)[0]].address

@krzkaczor
Copy link
Member

I think it's outside typechain scope since you don't deploy contract with typechain but manually.

What I would suggest is that you might want to deploy a contract called "universe" holding addresses of all other contracts. Then you just provide via env variable address to universe contract and get all other contracts when the app starts.

Examples: https://github.com/Neufund/platform-frontend/blob/master/app/lib/web3/ContractsService.ts#L69

Does it help?

@krzkaczor
Copy link
Member

Reopen please if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants