小编Viv*_*vek的帖子

如何在 Typescript 中将 BigNumber 转换为普通数字

伙计们,我正在从智能合约中获取数据,它给出了一个很大的数字作为响应,我想将其转换为正常数字,以便我可以使用它来创建条形图。如何才能做到这一点? 在此输入图像描述

这是我编写的代码片段,以便我可以将值存储在数组中:

//Creating candidatevoterarray for graph
    for (var i =0; i<= 4; i++){
        const temparray = this.candidatearray[i]
        const count = temparray.voteCount
        // this.candidatevotearray.push(count)
        console.log(count)
  }
Run Code Online (Sandbox Code Playgroud)

javascript typescript smartcontracts angular

10
推荐指数
1
解决办法
3万
查看次数

MetaMask - RPC 错误:尝试连接到智能合约时执行已恢复{代码:-32000,消息:'执行已恢复'}

我已经在公共测试网上部署了一个智能合约,现在我尝试使用 ethers js 从前端连接到它。但是当我尝试获取该值时,它会在控制台中出现以下错误:

在此输入图像描述

我使用 Angular 作为前端,这是我编写的代码:

declare let window: any;
import { Component, OnInit } from '@angular/core';
import { ethers } from 'ethers';
import addresses from '../../environment/contract-address.json'
import Election from '../../blockchain/artifacts/blockchain/contracts/Election.sol/Election.json'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'angvote';
  public signer: any;
  public electionContract: any;
  public candidate : any;
  public candidatesList:string[] | undefined;
  constructor(){}

  async ngOnInit(){
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    window.ethereum.enable()
    
    provider.on("network",(newNetwork: any, oldNetwork: any)=>{
      if (oldNetwork){
        window.location.reload();
      } …
Run Code Online (Sandbox Code Playgroud)

ethereum solidity ethers.js

5
推荐指数
2
解决办法
2万
查看次数

TypeError:无法读取 React 项目中 null 的属性“长度”

代码看起来没问题,但是却出现了这个错误。它说 TypeError: Cannot read property 'length' of null in React Project. 我已经发布了下面的代码。我正在使用 React Js 来构建它。请帮助。

import React, {useEffect} from 'react'
import { Link } from 'react-router-dom'
import { useDispatch, useSelector } from 'react-redux'
import { Row, Col, ListGroup, Image, Form, Button, Card } from 'react-bootstrap'
import Message from '../components/Message'
import { addToCart } from '../actions/cartActions'

function CartScreen({ match, location, history }) {
    const productId = match.params.id
    const qty = location.search ? Number(location.search.split('=')[1]) : 1
    
    const dispatch = useDispatch()

    const cart …
Run Code Online (Sandbox Code Playgroud)

javascript typeerror reactjs

2
推荐指数
1
解决办法
3万
查看次数