magic_flutter 1.0.0 copy "magic_flutter: ^1.0.0" to clipboard
magic_flutter: ^1.0.0 copied to clipboard

discontinuedreplaced by: magic_sdk
outdated

A Flutter plugin for Magic SDK

magic_flutter #

License: MIT Flutter Platform Badge

This is a specialized package that includes platform-specific implementation code for Android and iOS side Magic sdk implementation.

Features implemented #

  • Login with Magic sdk
  • Logout functionality
  • Update email
  • Check User's balance
  • Send BNB to other user
  • Get user's account address

How to use #

  • First of all get your publisher key from Magic sdk And initialize magic sdk
FutureBuilder(
        future: Magic.initializeMagic(
            publisherKey: //your key here
            ),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            if (snapshot.hasData) {
             return Container(
                alignment: Alignment.center,
                child: Text(
                    "Successfully initialized Magic"),
              );
            } else {
              return Container(
                alignment: Alignment.center,
                child: Text("Something went wrong. Failed to initialize Magic"),
              );
            }
          } else
            return Center(child: CircularProgressIndicator());
        },
      )
  • Once you have intialized sdk you can login with email
 await Magic.loginWithMagicLink(email: "test@gmail.com");
  • We can logout using logout function which returns a boolean that indicate successfull operation
bool value = await Magic.logout();
  • We can also check if user is already Logged in or not, it also returns a bool value that indicated if user is logged in.
bool value = await Magic.isLoggedIn();
  • After login we can get meta data, which return GetMetaDataResponse that contains three values email, issuer and publicAddress
FutureBuilder<GetMetaDataResponse>(
        future: Magic.getMetaData(),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            if (snapshot.hasData) {
             return Container(
                alignment: Alignment.center,
                child: Text(snapshot.data!.email),
              );
            } else {
              return Container(
                alignment: Alignment.center,
                child: Text("Something went wrong. Failed to get metadata"),
              );
            }
          } else
            return Center(child: CircularProgressIndicator());
        },
      )

Blockchain related methods #

If you want to do blockchain transactions follow this section

First of all intialize Magic sdk with CustomNodeConfiguration #

Magic.initializeMagic(
            publisherKey: publisherKey,
            rpcURL: "https://data-seed-prebsc-1-s1.binance.org:8545/",   // Smart Chain - Testnet RPC URL
            chainID: "97" // Smart Chain - Testnet chain 
            )
  • Once initialized you can Login and get meta data (need to get user account address)

Check user balance, it returns balance in BNB [String] #

 String value = await Magic.getUserBalance(
     accountAddress: //Enter user account address here);

Send transaction #

For Android #

  • You have to pass these values with amount in BNB [String], it will return transaction hash on successfull transaction.
String value = await Magic.sendTransaction(
          from: userAccountAddress,
          to: receiverAddress,
          amount: sendAmount,
          gasLimit: "21000",
          gasPrice: "10000000000");

For IOS #

  • You have to pass only from, to and amount parameter, it will return transaction hash on successfull transaction.
String value = await Magic.sendTransaction(
          from: userAccountAddress,
          to: receiverAddress,
          amount: sendAmount);
5
likes
0
points
42
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for Magic SDK

Repository (GitLab)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on magic_flutter

Packages that implement magic_flutter