Getting Started
Connecting to a Network
Learn how to connect to Polkadot and other Substrate-based networks using Polkadart
After installing Polkadart and generating types, you're ready to connect to a network and start querying the blockchain.
Setting Up Your Connection
Using Provider with Generated APIs
Create a new file bin/demo.dart and add the following code:
demo.dart
Future<void> main(List<String> arguments) async {
final provider = Provider.fromUri(Uri.parse('wss://rpc.polkadot.io'));
final polkadot = Polkadot(provider);
final query = await polkadot.rpc.state.getRuntimeVersion();
print(query.toJson());
}
Running Your Application
Execute your application with:
dart run bin/demo.dart
Expected Output
You should see the runtime version of the Polkadot chain:
{
specName: polkadot,
implName: parity-polkadot,
authoringVersion: 0,
specVersion: 1003003,
implVersion: 0,
apis: [...],
transactionVersion: 26,
stateVersion: 1
}
🎉 Success! You've successfully connected to Polkadot and made your first query to the chain!
Connecting to Different Networks
final provider = Provider.fromUri(Uri.parse('wss://rpc.polkadot.io'));
final provider = Provider.fromUri(Uri.parse('wss://kusama-rpc.polkadot.io'));
final provider = Provider.fromUri(Uri.parse('wss://westend-rpc.polkadot.io'));
final provider = Provider.fromUri(Uri.parse('ws://127.0.0.1:9944'));
Pro Tip: For production applications, consider using multiple RPC endpoints for redundancy and load balancing.
Connection Options
You can customize your connection with additional options:
final provider = Provider.fromUri(
Uri.parse('wss://rpc.polkadot.io'),
// Add connection options here if needed
);