Skip to content

Instantly share code, notes, and snippets.

@ishwarchandratiwari
Created March 28, 2019 20:27
Show Gist options
  • Save ishwarchandratiwari/eedf4b34ef6887e5441879ab7f9749cd to your computer and use it in GitHub Desktop.
Save ishwarchandratiwari/eedf4b34ef6887e5441879ab7f9749cd to your computer and use it in GitHub Desktop.
web3 connection in flutter
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
void main() {
runApp(MaterialApp(
home: EthApp(),
title: 'web3 flutter app',
));
}
class EthApp extends StatefulWidget {
@override
_EthAppState createState() => _EthAppState();
}
class _EthAppState extends State<EthApp> {
@override
void initState() {
_loadBalance();
super.initState();
}
void _loadBalance() async {
var _client = Web3Client(
'https://mainnet.infura.io/v3/ie8b3da9156fd4b4f8f8cdac7e085e1e0',
Client());
final int BlockNumber = await _client.getBlockNumber();
print(BlockNumber);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('web3 flutter'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.center,
child: Column(
mainAxisSize: MainAxisSize.min,
children: 'this is just a demo',
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment