Interact with the smart contract details
All right! So you've deployed you smart contract through the SCUI! Lets show the end-user the contract details and if possible, interact with the contract as well.
So, if you clicked on the finish button after the last deployment step, you would have been redirected to this screen:

The contract/:contractAddress/show/:contractType page.
This page displays the contract details that were setup in the contract/:contractType/create page. Easy, right?
Let's have a look at what this component looks like.
Create the fixed-supply component inside the contract-show module
The component must be generated by the angular cli and you should be ready to get your contract details.
Display the fixed-supply component with the matching :contractType param
Get the fixed-supply contract details
By now, you should be familiar with the frontend framework, so here's the whole component code.
Basically, what is happening here is:
Init the component with
ngOnInit()Get the
contractAddressfrom the route paramsInitialize a new
SimpleCrowdsaleContractinstance passing the Wallet instanceConnect to the contract ABI and set the
contractAddressfrom the routeThis is equivalent to passing the address to the new
web3.eth.Contractcall or calling newContract().at()in other libraries
Subscribe to the crowdsale contract events. These events are the transactions happening for this contract in the Ethereum network. Web3 listens to these events using websockets
Instantiate a new
SimpleTokenContractpassing theWalletinstance and connect to its ABIGet the crowdsale data. Note that we are delegating these methods to the
SimpleCrowdsaleContractclass. This is a good design practiceGet the token data. Because the crowdsale contract has the token address stored in it, we can get it by calling the
this.crowdsale.instance.methods.token.call()method. Await for it to return the value and set the address to the token contract instance
Whenever a transaction happens for this crowdsale smart contract in the Ethereum address, the subscription will populate the txHistory array and display it in the SCUI in real-time.
This is how the SCUI html looks like. Note that we are binding to the crowdsale and token instances. This is a good design practice. Also the template will show the data whenever it is ready or it changes:
Last updated