Integrate Embedded Wallets with the Songbird Blockchain in Flutter
While using the Embedded Wallets Flutter SDK, you get the private key within the user scope after successful authorization. This private key can be used to retrieve the user's address, and interact with Songbird to make any blockchain calls. We have highlighted a few here for getting you started quickly on that.
Prerequisites
This doc assumes you have already setup your project in the Embedded Wallets Dashboard (formerly Web3Auth), and have integrated Embedded Wallets in your Flutter app. If you haven't done that yet, you can learn how to integrate Embedded Wallets in your Flutter app.
Installation
To interact with the Ethereum compatible blockchains in Flutter, you can use any EIP1193
compatible package. Here, we're using web3dart to demonstrate how to make blockchain calls using it with Embedded Wallets (formerly Web3Auth).
To install the web3dart
package, you have two options. You can either manually add the package in the pubspec.yaml
file, or you can use the flutter pub add
command.
- Console
- Pubspec
Add web3dart
using flutter pub add
command.
flutter pub add web3dart
Add web3dart
as a dependency to your pubspec.yaml
.
dependencies:
web3dart: ^2.7.3
Initialize
We'll initialize the Web3Client
with the RPC URL of the network you want to connect to. This
client allows us to interact with the blockchain. To get the public RPC URL, you can checkout
chainlist.org.
import 'package:web3dart/web3dart.dart';
// Please avoid using public RPC URL in production, use services
// like Infura, Quicknode, etc.
final client = Web3Client("YOUR_RPC_URL", Client());