Setup smart contract constructor params
Learn how to connect a Solidity smart contract ABI with the SCUI
Understanding the create SCUI workflow
In this chapter, we will connect a user interface with HTML form inputs to setup the NAME, SYMBOL and SUPPLY of a new ERC20 token contract and the PRICE and BENEFICIARY ADDRESS of a fixed-supply crowdsale contract that will take charge of selling the ERC20 token for us.
The rationale of this fixed-supply crowdsale is that any end-user could get or scan the QRCode of the ETH address of the crowdsale contract, transfer ETH to it and if the crowdsale still has token supply, take the ETH and send the ERC20 token to the buyer if the buyer meets the price.
Also, if the buyer sends more ETH than what the ERC20 costs, the crowdsale contract takes charge of delivering the remaining ETH back.
Fixed-supply contract SCUI end result:

Required contracts
In order to create a complete fixed-supply crowdsale creation flow, we need 2 contracts.
SimpleTokenContract
Extends from the open-zeppelin StandardToken and DetailedERC20.
In the constructor we set the value of a supply public variable multiplied by 1 ETH. This is important as the end-user deploying the new ERC20 will specify a supply as ETH integers and not it WEI.
SimpleCrowdsaleContract
The SimpleCrowdsaleContract extends from the standard open-zeppelin crowdsale contract and modifies some of its methods, basically to give back the remaining ETH if the value is higher than the price stored in the crowdsale.
Using the contracts ABI in the fixed-supply crowdsale SCUI
A compiled version of these contracts should be put in the src/assets/contracts/ directory of the web-app:
Then, it is ready to be used.
Add a user interface for configuring the smart contract constructor params
The contract/:contractType/create is designed to add HTML components that allow the end-user to interact with the constructor params of our smart contract.
Generate the fixed-supply component
In your terminal, execute:
This will create a new component inside the contract-create module.
Let the parent contract-create container component decide what contract type component to display
This part takes 2 steps:
Adding the FixedSupplyDeployment _type string to the parent container component
FixedSupplyDeployment _type string to the parent container componentAdding the component element to the container.component.html element
container.component.html elementSetup the FixedSupplyComponent
Open the fixed-supply.component.ts file and add the ContractDeploymentFactory to it. This will make the FixedSupplyDeployment class available in the FixedSupplyComponent:
Initialize the fixed-supply crowdsale smart contract
Once you've integrated the deployer with the component, the next step is to integrate the smart contract ABI with the UI.
In the ngOnInit() method of our FixedSupplyComponent, we are calling 3 deployer methods: createToken(), createCrowdsale() and createSimpleICO()
Connecting to a smart contract interface, ABI
The missing third method called in our component lives in the parent ContractDeployment class:
Note the .connect() method common in the 3 of the contract class instances. This method is defined in each of the *Contract classes.
Defining a *Contract class
*Contract classes are in charge of interacting with the compiled Solidity smart contract ABI. This will allow us to call any Solidity contract methods through the deployer like this:
Let's create the fixed-supply crowdsale contract class and place it in the src/app/@contract/ directory of our app:
Naming convention
For *Contract classes, the suggested naming convention is <contract-name>.contract.ts
Notice that the constructor passes the Wallet instance to the parent Crowdsale contract. The parent Crowdsale contract is used as a generic class, in case you need common methods or properties across other Crowdsale contracts.
Also, we are getting the web3 instance from the Wallet so we can access the Web3JS package methods.
Finally, the connect() method is using the web3 instance to initialize the contract using the ABI as detailed in the docs (http://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#new-contract)
We will do the same for the SimpleTokenContract class and the SimpleICOContract classes:
Last updated