通过Nethereum获得链上资产余额。
这里通过主链Url生成一个Web3的实例,调用GetBalance方法获得。
///
/// 获得账户余额
///
/// 主链地址
/// 账户地址
///
private decimal getChainBalance(string url,string address)
{
Web3 web3 = new Web3(url);
//获得余额
var result = web3.Eth.GetBalance.SendRequestAsync(address);
result.Wait();
//wei转换为eth
var balanceEther = Web3.Convert.FromWei(result.Result.Value);
//保留小数点后8位
balanceEther = decimal.Round(balanceEther, 8, MidpointRounding.AwayFromZero);
return balanceEther;
}
百度网盘: https://pan.baidu.com/s/1LTC12Eurrfs681FJPloktw 提取码: 7789
QQ交流群:103446157
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)