Flutter插件ord_dart的使用指南

简介

ord_dart是一个与 Ordinals 协议相关的库,目前支持运行符(runes)协议。它允许开发者在 Dart 和 Flutter 应用程序中实现与 Ordinals 协议相关的功能。

ord_dart


ord_dart使用步骤

1. 安装依赖

由于 ord_dart 依赖于 cargokit,你需要通过 rustup 安装 Rust 环境才能使用它。完成后,在 pubspec.yaml 文件中添加以下依赖:

dependencies:
  ord_dart: $latest_version

然后运行 flutter pub get 来安装依赖。


示例代码

以下是几个常见的用法示例,展示了如何在 Flutter 中使用 ord_dart

1. 刻字(Etching)

刻字操作用于定义一种新的运行符(rune)。以下是一个完整的刻字示例:

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:ord_dart/ord_dart.dart';

void main() async {
  await OrdDart.init(); // 初始化 ord_dart
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  Uint8List getEncipher() {
    final etching = Etching(
      divisibility: 2, // 可分割性
      premine: BigInt.from(11000000000), // 预挖数量
      rune: Rune.fromStr(s: "ZZZZZFEHUZZZZZ"), // 运行符字符串
      spacers: 7967, // 分隔符
      symbol: "ᚠ", // 符号
      terms: Terms(
        amount: BigInt.from(100), // 每次铸造的数量
        cap: BigInt.from(1111111), // 总量上限
        height: null, // 区块高度(可选)
        offset: null, // 偏移量(可选)
      ),
      turbo: true, // 启用 Turbo 模式
    );
    final runestone = Runestone(etching: etching); // 创建 Runestone 对象
    return runestone.encipher(); // 返回加密结果
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('ord_dart quickstart')),
        body: Center(
          child: Text(
            'Action: Call Rust `RuneStone.encipher`\n'
            'Result: `${getEncipher().toString()}...`', // 显示部分结果
          ),
        ),
      ),
    );
  }
}

2. 铸造(Mint)

铸造操作用于创建一个新的运行符实例。以下是一个简单的铸造示例:

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:ord_dart/ord_dart.dart';

void main() async {
  await OrdDart.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  Uint8List getEncipher() {
    final runestone = Runestone(
      mint: RuneId.fromStr(s: "840000:1"), // 运行符 ID
    );
    return runestone.encipher();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('ord_dart quickstart')),
        body: Center(
          child: Text(
            'Action: Call Rust `RuneStone.encipher`\n'
            'Result: `${getEncipher().toString()}...`',
          ),
        ),
      ),
    );
  }
}

3. 转移(Transfer)

转移操作用于将运行符从一个地址转移到另一个地址。以下是一个简单的转移示例:

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:ord_dart/ord_dart.dart';

void main() async {
  await OrdDart.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  Uint8List getEncipher() {
    final runestone = Runestone(
      edicts: [
        Edict(
          id: RuneId.fromStr(s: "840000:1"), // 运行符 ID
          amount: BigInt.from(100), // 转移数量
          output: 1, // 输出索引
        )
      ],
    );
    return runestone.encipher();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('ord_dart quickstart')),
        body: Center(
          child: Text(
            'Action: Call Rust `RuneStone.encipher`\n'
            'Result: `${getEncipher().toString()}...`',
          ),
        ),
      ),
    );
  }
}

更多功能

更多示例代码可以在官方仓库查看:ord_dart 示例代码


许可证

ord_dart 的许可证为 MIT。你可以自由地使用、修改和分发该库。完整的许可证信息可以在这里查看:LICENSE

MIT License

Copyright (c) 2024 AstroxNetwork

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

更多关于Flutter插件ord_dart的使用指南的实战教程也可以访问 https://www.itying.com/category-92-b0.html

回到顶部