Flutter加密货币价格查询插件shitcoin_price的使用
Flutter加密货币价格查询插件shitcoin_price的使用
Package Info
此插件使用每个路由器的池合约和不同的加密货币交易平台来获取任何代币的价格,即使这些代币未经过验证。它是免费的,无需任何API密钥或注册。😎
Features
可以在以太坊网络及其子网(如Binance Smart Chain、Polygon等)上获取任意代币的对价。
Getting Started
在你的pubspec.yaml
文件中添加该包,如下所示:
dependencies:
shitcoin_price: any
然后在代码中导入该包,如下所示:
import 'package:shitcoin_price/shitcoin_price.dart';
Usage
你可以调用函数并传入所需的参数来查询价格,例如:
String rpc = 'https://bsc-dataseed1.binance.org/';
String router = '0x10ed43c718714eb63d5aa57b78b54704e256024e';
String token0 = '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82';
String token1 = '0xe9e7cea3dedca5984780bafc599bd69add087d56';
final httpClient = Client();
final provider = Web3Client(rpc, httpClient);
final priceDouble = await ShitCoinPrice().asDouble(provider, router, token0, token1);
print(priceDouble); // 1.7973780251387401 CAKE
或者:
String rpc = 'https://bsc-dataseed1.binance.org/';
String router = '0x10ed43c718714eb63d5aa57b78b54704e256024e';
String token0 = '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82';
String token1 = '0xe9e7cea3dedca5984780bafc599bd69add087d56';
final httpClient = Client();
final provider = Web3Client(rpc, httpClient);
final priceBigInt = await ShitCoinPrice().asBigInt(provider, router, token0, token1);
print(priceBigInt); // 1797378025138740195 CAKE
更多关于Flutter加密货币价格查询插件shitcoin_price的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复
更多关于Flutter加密货币价格查询插件shitcoin_price的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
shitcoin_price
是一个用于 Flutter 应用的插件,用于查询加密货币的价格。它允许你获取各种加密货币的实时价格信息。以下是如何在 Flutter 项目中使用 shitcoin_price
插件的步骤:
1. 添加依赖
首先,你需要在 pubspec.yaml
文件中添加 shitcoin_price
插件的依赖:
dependencies:
flutter:
sdk: flutter
shitcoin_price: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来安装依赖。
2. 导入插件
在你的 Dart 文件中导入 shitcoin_price
插件:
import 'package:shitcoin_price/shitcoin_price.dart';
3. 使用插件
你可以使用 ShitcoinPrice
类来获取加密货币的价格。以下是一个简单的示例:
class CryptoPriceScreen extends StatefulWidget {
[@override](/user/override)
_CryptoPriceScreenState createState() => _CryptoPriceScreenState();
}
class _CryptoPriceScreenState extends State<CryptoPriceScreen> {
double btcPrice = 0.0;
double ethPrice = 0.0;
[@override](/user/override)
void initState() {
super.initState();
fetchPrices();
}
Future<void> fetchPrices() async {
// 获取比特币价格
double btc = await ShitcoinPrice.getPrice('bitcoin');
// 获取以太坊价格
double eth = await ShitcoinPrice.getPrice('ethereum');
setState(() {
btcPrice = btc;
ethPrice = eth;
});
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Cryptocurrency Prices'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Bitcoin Price: \$${btcPrice.toStringAsFixed(2)}'),
SizedBox(height: 20),
Text('Ethereum Price: \$${ethPrice.toStringAsFixed(2)}'),
],
),
),
);
}
}