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:

contract/0x1234.../fixed-supply/show

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:

  1. Init the component with ngOnInit()

  2. Get the contractAddress from the route params

  3. Initialize a new SimpleCrowdsaleContract instance passing the Wallet instance

  4. Connect to the contract ABI and set the contractAddress from the route

    1. This is equivalent to passing the address to the new web3.eth.Contract call or calling new Contract().at() in other libraries

  5. 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

  6. Instantiate a new SimpleTokenContract passing the Wallet instance and connect to its ABI

  7. Get the crowdsale data. Note that we are delegating these methods to the SimpleCrowdsaleContract class. This is a good design practice

  8. Get 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