current position:Home>Verification and transfer of Ethereum balance and token balance

Verification and transfer of Ethereum balance and token balance

2022-02-03 23:23:04 Q & A of Denglian community

    // Check the balance     balance,err := client.BalanceAt(context.Background(),msg.From,big.NewInt(int64(blockNumber)))    if err != nil {        fmt.Println("GetBalanceAt Error:", err)        return    }
    // take balance To eth Company     fBalance := new(big.Float)    fBalance.SetString(balance.String())    ethBalance := new(big.Float).Quo(fBalance,big.NewFloat(math.Pow10(18)))    fmt.Println("ethBalance:",ethBalance)    // Set minimum balance     lessBalance := new(big.Int).SetUint64(uint64(8000000000000000))    fmt.Println("lessBalance:",lessBalance)//800,000,000,000,000,0    lfBalance := new(big.Float)    lfBalance.SetString(lessBalance.String())    lethBalance := new(big.Float).Quo(lfBalance,big.NewFloat(math.Pow10(18)))    fmt.Println("lethBalance:",lethBalance)//0.008    // Compare whether the current balance is lower than the minimum balance     if ethBalance < lethBalance {        fmt.Println(" Lack of balance ")    }

After using the above method to obtain Ethereum balance , When you want to compare the balance with the set minimum balance , Tips operator < not defined on *Float, How should I compare whether the balance reaches the user-defined number ? And how to get ERC20 Token balance and token transfer

Take the answer 1:

I haven't done that , But after the algorithm is a large integer , Subtract Determine whether Greater than 0 You can to .

ERC20 The balance of tokens : Call... On the token contract address balanceOf function . Transfer accounts : call transfer function . Reference resources ERC20 standard :

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.

Random recommended