A client library to interact with ArchethicWallet RPC API.
Check AEIP-4 to know more.
$ flutter pub add archethic-wallet-client
If your application is intended to work on Android or iOS, you must setup a Deeplink endpoint on your application.
This is required to get DeeplinkRPC to work.
A queries
element must be added to your manifest as a child of the root element.
<queries>
<!-- AEWallet deeplink support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data
android:scheme="aewallet"
android:host="archethic.tech" />
</intent>
</queries>
Add a meta-data
tag and intent filter
to AndroidManifest.xml
inside the activity
tag with the ".MainActivity" name:
<!-- AEWallet deeplink support -->
<meta-data
android:name="flutter_deeplinking_enabled"
android:value="true" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Replace `flutterdappexample` by your custom deeplink scheme -->
<!-- Replace `dapp.example` by your custom deeplink host -->
<!-- These will be used to compose the replyUrl when sending RPCs -->
<data
android:scheme="flutterdappexample"
android:host="dapp.example" />
</intent-filter>
Add LSApplicationQueriesSchemes
entries in your Info.plist
file.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>aewallet</string>
</array>
Add two new keys to Info.plist
in the ios/Runner
directory:
<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<!-- Replace `flutterdappexample` by your custom deeplink scheme -->
<!-- Replace `dapp.example` by your custom deeplink host -->
<!-- These will be used to compose the replyUrl when sending RPCs -->
<key>CFBundleURLName</key>
<string>dapp.example</string>
<key>CFBundleURLSchemes</key>
<array>
<string>flutterdappexample</string>
</array>
</dict>
</array>
Add:
<key>com.apple.security.network.client</key>
<true/>
to macos/Runner/DebugProfile.entitlements
and macos/Runner/Release.entitlements
.
import 'package:archethic-wallet-client/archethic-wallet-client.dart';
// 1. Instanciate a Client
final _aewalletClient = ArchethicDAppClient.auto(
origin: const RequestOrigin( // Sets Dapp identity informations. Might be displayed to the user.
name: 'FlutterDappExample',
),
replyBaseUrl: 'flutterdappexample://dapp.example', // Deeplink Dapp endpoint
);
Handle incoming deeplinks in the onGenerateRoute
method :
// 2. Listens to deeplink responses
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Dapp Demo',
home: MyHome(),
onGenerateRoute: (settings) {
if ((_aewalletClient as DeeplinkArchethicDappClient)
.handleRoute(settings.name)) return;
//... do everything else needed by your application
return null;
},
);
}
}
final response = await _aewalletClient.sendTransaction(
transactionJsonData,
);
response.when(
failure: (failure) {
log(
'Transaction failed',
error: failure,
);
},
success: (result) {
log(
'Transaction succeed : ${json.encode(result)}',
);
},
);
There are two kinds of methods :
- one time call
- subscriptions.
Subscriptions won't be available on Deeplink channel because of technical limitations.
Gets the endpoint URL used on AEWallet.
// no payload in request
{
"endpointUrl": String // Endpoint URL
}
Request the wallet to refresh current account info
// no payload in request
// no response
Gets the accounts available on AEWallet.
// No payload
{
"accounts": [
{
"shortName": String, // Account name
"serviceName": String // Service name
"genesisAddress": String, // Genesis address
}
]
}
Signs and sends a transaction.
{
"type": String, // Type of transaction
"version": Number, // Version of the transaction (used for backward compatiblity)
"data": Object, // Transaction data zone (identity, keychain, smart contract, etc.)
"generateEncryptedSeedSC": bool // (Optional) : if true, add a encrypted (by storage nonce public key) seed in the transaction's ownerships to allow nodes to manage smart contract
}
{
"transactionAddress": String, // Sent transaction address.
"nbConfirmations": Number, // Number of received confirmations.
"maxConfirmations": Number, // Max number of confirmations.
}
Add a service in the keychain
{
"name": String, // Name of the service
}
{
"transactionAddress": String, // Transaction address.
"nbConfirmations": Number, // Number of received confirmations.
"maxConfirmations": Number, // Max number of confirmations.
}
Remove a service from the keychain
{
"name": String, // Name of the service
}
{
"transactionAddress": String, // Transaction address.
"nbConfirmations": Number, // Number of received confirmations.
"maxConfirmations": Number, // Max number of confirmations.
}
Gets keychain's services from the keychain connected to AEWallet.
// No payload
{
"services": [
{
"derivationPath": String, // Derivation path
"curve": String, // Curve
"hashAlgo": String // Hash Algo
}
]
}
Derive a keypair for the given service at the index given and get the public key
{
"serviceName": String, // Service name to identify the derivation path to use
"index": Number, // Chain index to derive (optional - default to 0)
"pathSuffix": String // Additional information to add to a service derivation path (optional - default to empty)
}
{
"publicKey": String // Public key of the service at the index given
}
Derive an address for the given service at the index given
{
"serviceName": String, // Service name to identify the derivation path to use
"index": Number, // Chain index to derive (optional - default to 0)
"pathSuffix": String // Additional information to add to a service derivation path (optional - default to empty)
}
{
"address": String // Address derived
}
Gets the current account selected on AEWallet.
// No payload
{
"shortName": String, // Account name
"serviceName": String // Service name
"genesisAddress": String, // Genesis address
}
Signs many transactions.
{
"serviceName": String, // Service name to use to sign the tx
"pathSuffix": String, // Additional information to add to a service derivation path (optional)
"description": String { // Readable description to explain the purpose of signing transactions (locale + description)
"en": "Readable description in English",
"fr": "Description lisible en français",
},
"transactions": [
{
"type": String, // Type of transaction
"version": Number, // Version of the transaction (used for backward compatiblity)
"data": Object // Transaction data zone (identity, keychain, smart contract, etc.)
}
]
}
{
"signedTxs": [
{
"address": String, // Address: hash of the new generated public key for the given transaction
"previousPublicKey": String, // Previous generated public key matching the previous signature
"previousSignature": String, // Signature from the previous public key
"originSignature": String // Signature from the device which originated the transaction (used in the Proof of work)
}
]
}
Signs many payloads.
{
"serviceName": String, // Service name to use to sign the payload
"pathSuffix": String, // Additional information to add to a service derivation path (optional)
"description": String { // Readable description to explain the purpose of signing payloads (locale + description)
"en": "Readable description in English",
"fr": "Description lisible en français",
},
"payloads": [
{
"payload": String, // Payload to sign
"isHexa": boolean // Precise if the payload if in hexadecimal format
}
]
}
{
"signedPayloads": [
{
"signedPayload": String, // Signed payload
}
]
}
Encrypt many payloads with account public key.
{
"serviceName": String, // Service name to use to encrypt the payload
"pathSuffix": String, // Additional information to add to a service derivation path (optional)
"payloads": [
{
"payload": String, // Payload to encrypt
"isHexa": boolean // Precise if the payload if in hexadecimal format
}
]
}
{
"encryptedPayloads": [
{
"encryptedPayload": String, // Encrypted payload
}
]
}
Decrypt many payloads with account private key.
{
"serviceName": String, // Service name to use to decrypt the payload
"pathSuffix": String, // Additional information to add to a service derivation path (optional)
"description": String { // Readable description to explain the purpose of decrypting payloads (locale + description)
"en": "Readable description in English",
"fr": "Description lisible en français",
},
"payloads": [
{
"payload": String, // Payload to decrypt
"isHexa": boolean // Precise if the payload if in hexadecimal format
}
]
}
{
"decryptedPayloads": [
{
"decryptedPayload": String, // Decrypted payload
}
]
}