Create a new contract deployment type class

This tutorial assumes that you've already installed and served the web-app

Installation

The ContractDeploymentFactory

The first step in the SCUI pattern, is to create a ContractDeploymentInterface type class.

This class will take charge of deploying your smart contract or executing your smart contract methods as well as know how to calculate the transaction costs of these actions.

The smart contract, or set of smart contracts we will be deploying to the Ethereum mainnet and ropsten testnet networks are fixed-supply crowdsale contracts.

Adding a ContractDeployment class to the factory

Create a new file inside src/app/@factory called: fixed-supply.deployment.ts

Naming convention

For contract deployment type classes, the suggested naming convention is: <contract-type>.deployment.json

This is the basic structure of the file, note that it extends from the ContractDeployment class and that it implements ContractDeploymentInterface for typing and generics purposes:

https://github.com/SimpleICO/web-app/blob/master/src/app/%40factory/fixed-supply.deployment.ts
import { ContractDeployment, ContractDeploymentInterface } from '@factory/contract-deployment';
import { Wallet } from '@model/wallet.model';
import { EthereumService } from '@service/ethereum.service';

export class FixedSupplyDeployment
  extends ContractDeployment
  implements ContractDeploymentInterface {

  static readonly _type: string = 'fixed-supply'

  type: string

  constructor(wallet: Wallet, eth: EthereumService){
    super(wallet, eth)

    this.type = FixedSupplyDeployment._type
  }
}

In line :7 of the previous code block, define the type of the ContractDeployment class as a string. This string is very important as it is used across all the contract routes of our application. This string should not be equal amongst other ContractDeployment classes.

The ContractDeploymentFactory will take charge of passing the Wallet and the EthereumService instance to the constructor. This is needed for the ContractDeployment class to use the wallet information such as the balance, the ETH address, and so on.

The EthereumService is used to calculate gas costs and for converting ETH to another currency in case you need it.

Last updated