A client library to interact with ArchethicWallet RPC API.
What is ArchethicWallet RPC
Check AEIP-4 to know more.
Usage
Add dependency
$ flutter pub add archethic-wallet-client
Setup Deeplink
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.
Android
A queries element must be added to your manifest as a child of the root element.
<queries>
<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:
<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" />
<data
android:scheme="flutterdappexample"
android:host="dapp.example" />
</intent-filter>
iOS
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>
<key>CFBundleURLName</key>
<string>dapp.example</string>
<key>CFBundleURLSchemes</key>
<array>
<string>flutterdappexample</string>
</array>
</dict>
</array>
Other Native setups
MacOS
Add:
<key>com.apple.security.network.client</key>
<true/>
to macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements.
Client setup
Instanciate a client
import 'package:archethic-wallet-client/archethic-wallet-client.dart';
final _aewalletClient = ArchethicDAppClient.auto(
origin: const RequestOrigin(
name: 'FlutterDappExample',
),
replyBaseUrl: 'flutterdappexample://dapp.example',
);
[Deeplink only] Listen to deeplink responses
Handle incoming deeplinks in the onGenerateRoute method :
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;
return null;
},
);
}
}
Emit requests
final response = await _aewalletClient.sendTransaction(
transactionJsonData,
);
response.when(
failure: (failure) {
log(
'Transaction failed',
error: failure,
);
},
success: (result) {
log(
'Transaction succeed : ${json.encode(result)}',
);
},
);
RPC Methods
There are two kinds of methods :
- one time call
- subscriptions.
Subscriptions won't be available on Deeplink channel because of technical limitations.
get_endpoint
Gets the endpoint URL used on AEWallet.
Request
Success Response
{
"endpointUrl": String
}
refresh_current_account
Request the wallet to refresh current account info
Request
Success Response
get_accounts
Gets the accounts available on AEWallet.
Request
Success Response
{
"accounts": [
{
"shortName": String,
"serviceName": String
"genesisAddress": String,
}
]
}
send_transaction
Signs and sends a transaction.
Request
{
"type": String,
"version": Number,
"data": Object,
"generateEncryptedSeedSC": bool
}
Success Response
{
"transactionAddress": String,
"nbConfirmations": Number,
"maxConfirmations": Number,
}
add_service
Add a service in the keychain
Request
{
"name": String,
}
Success Response
{
"transactionAddress": String,
"nbConfirmations": Number,
"maxConfirmations": Number,
}
remove_service
Remove a service from the keychain
Request
{
"name": String,
}
Success Response
{
"transactionAddress": String,
"nbConfirmations": Number,
"maxConfirmations": Number,
}
get_services_from_keychain
Gets keychain's services from the keychain connected to AEWallet.
Request
Success Response
{
"services": [
{
"derivationPath": String,
"curve": String,
"hashAlgo": String
}
]
}
keychain_derive_keypair
Derive a keypair for the given service at the index given and get the public key
Request
{
"serviceName": String,
"index": Number,
"pathSuffix": String
}
Success Response
{
"publicKey": String
}
keychain_derive_address
Derive an address for the given service at the index given
Request
{
"serviceName": String,
"index": Number,
"pathSuffix": String
}
Success Response
{
"address": String
}
get_current_account
Gets the current account selected on AEWallet.
Request
Success Response
{
"shortName": String,
"serviceName": String
"genesisAddress": String,
}
sign_transactions
Signs many transactions.
Request
{
"serviceName": String,
"pathSuffix": String,
"description": String {
"en": "Readable description in English",
"fr": "Description lisible en français",
},
"transactions": [
{
"type": String,
"version": Number,
"data": Object
}
]
}
Success Response
{
"signedTxs": [
{
"address": String,
"previousPublicKey": String,
"previousSignature": String,
"originSignature": String
}
]
}
sign_payloads
Signs many payloads.
Request
{
"serviceName": String,
"pathSuffix": String,
"description": String {
"en": "Readable description in English",
"fr": "Description lisible en français",
},
"payloads": [
{
"payload": String,
"isHexa": boolean
}
]
}
Success Response
{
"signedPayloads": [
{
"signedPayload": String,
}
]
}
encrypt_payloads
Encrypt many payloads with account public key.
Request
{
"serviceName": String,
"pathSuffix": String,
"payloads": [
{
"payload": String,
"isHexa": boolean
}
]
}
Success Response
{
"encryptedPayloads": [
{
"encryptedPayload": String,
}
]
}
decrypt_payloads
Decrypt many payloads with account private key.
Request
{
"serviceName": String,
"pathSuffix": String,
"description": String {
"en": "Readable description in English",
"fr": "Description lisible en français",
},
"payloads": [
{
"payload": String,
"isHexa": boolean
}
]
}
Success Response
{
"decryptedPayloads": [
{
"decryptedPayload": String,
}
]
}