Skip to main content

Installation

To interact with the Ethereum blockchain, Magic Flutter SDK embeds web3dart as sub dependency. No more extra dependency is needed.

Initialization

The Magic class is the entry-point to the Magic SDK. It must be instantiated with a Magic publishable key.
Dart
Dart

Use Different Networks

Testnet

Goerli Block Explorer: https://goerli.etherscan.io Goerli Testnet Faucet: https://goerlifaucet.com
Dart

Custom Node

You can allow specific URLs to interact with the Magic SDK, such as a custom RPC URL to send transactions to your node. The Content Security Policy (CSP) of a browser dictates what resources can be loaded. You can update the policy in the settings page of the dashboard with your custom URL.
NoteThe use of a custom node will require the RPC URL to the project’s Content Security Policy from your Magic Dashboard. Refer to the CSP documentation.
Dart
ImportantDo not set the custom nodes to local IP address (E.x. “http://127.0.0.1”). Local IP will point to the network environment inside the mobile device / simulator

Magic Credential

web3dart supports custodial design where the library will ask for user’s private key to sign the payloads. To integrate web3dart in non-custodial, We recommend you to use MagicCredential to optimize security.
Dart
ImportantYou will need to call MagicCredential getAccount() before other signing functions to get the public address that will be used from the current authenticated user.

Common Methods

Send Transaction

Dart

Sign Message

Magic Credential offers non-custodial signing apis

Eth Sign

Dart

Sign Typed Data Legacy (V1)

Dart

Sign Typed Data (EIP 712)

Dart

Get User Info

Dart

Smart Contract

In this example, we’ll be demonstrating how to use Magic with web3dart to interact with Solidity smart contracts. The simple Hello World contract allows anyone to read and write a message to it.
Solidity
Dart

Deploy Contract

Dart

Read from Contract

Dart

Write to Contract

Dart

Resources