Dart package for interfacing with the Arweave network, modelled after arweave-js.
arweave-dart is currently not available on pub.dev but you can use it by referencing this repository in your pubspec.yaml as shown below:
dependencies:
arweave:
git: https://github.com/CDDelta/arweave-dart.gitYou can optionally pin your dependency to a specific commit, branch, or tag to avoid possible breaking changes:
dependencies:
arweave:
git:
url: https://github.com/CDDelta/arweave-dart.git
ref: some-branchOnce you have the package, you can create an instance of the client with its default configuration:
import 'package:arweave/arweave.dart';
void main() {
var client = Arweave(api: ArweaveApi());
}This will create an instance of the client that connects to the arweave.net gateway (or on the web, the origin you're hosting on).
To use a custom gateway:
Arweave(api: ArweaveApi(gatewayUrl: Uri.parse('https://arweave.dev')));Loading an Arweave wallet can be done as shown below:
Wallet.fromJwk(json.decode('<wallet data>'));Creating transactions with arweave-dart is easy. First prepare a transaction like below, optionally adding some tags:
final transaction = await client.transactions.prepare(
Transaction.withBlobData(data: utf8.encode('Hello world!')),
wallet,
);
transaction.addTag('App-Name', 'Hello World App');
transaction.addTag('App-Version', '1.0.0');Secondly, sign the transaction:
await transaction.sign(wallet);Finally upload the transaction.
This can be done in a single call, useful for small transactions.
await client.transactions.post(transaction);Or progressively for more granularity.
await for (final upload in client.transactions.upload(transaction)) {
print('${upload.progress * 100}%');
}Use ANS-104 data bundles by first preparing some data items as so:
final dataItem = DataItem.withBlobData(
owner: wallet.owner,
data: utf8.encode('hello world'),
)
..addTag('MyTag', '0')
..addTag('OtherTag', 'Foo');
await dataItem.sign(wallet);and then creating the data bundle transaction:
final transaction = await client.transactions.prepare(
Transaction.withDataBundle(bundle: DataBundle(items: [dataItem])),
wallet,
);Dart's Base64 encoder/decoder is incompatible with Arweave's returned Base64 content, so arweave-dart exposes utilities for working with Base64 from Arweave. It also includes other utilities for AR/Winston conversions etc.
To use these utilities, import them like so:
import 'package:arweave/utils.dart' as utils;To rebuild the generated code (eg. for JSON serialisation) run:
dart pub run build_runner buildTo test, run the following command
dart test -p "chrome,vm"