Home > Software design >  Display result contained in let declaration Typescript
Display result contained in let declaration Typescript

Time:02-25

I am attempting to display the result of await this.contract.mint(amount, {value: this.state.tokenPrice.mul(amount)}). I would like to see what it outputs.

  async mintTokens(amount: number): Promise<void>
  {
    try {
      let showResult = await this.contract.mint(amount, {value: this.state.tokenPrice.mul(amount)});
      this.setState({
        successMessage: showResult,
      });
    } catch (e) {
      this.setError(e);
    }
  }

The code has error Type 'ContractTransaction' is not assignable to type 'string'. and I'm not quite sure how to fix this.

CodePudding user response:

you can just stringify the object:

...
      this.setState({
        successMessage: JSON.stringify(showResult),
      });
...
  • Related