bip21 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 48

bip-21 #

build status

Dart implementation of the BIP-21 Bitcoin URI scheme.

Based on the bitcoinjs implementation.

Example #

import 'dart:convert';
import 'package:bip21/bip21.dart';

main() {
  var decoded = Bip21.decode(
      "bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foobar");
  print(decoded.toJson());
  // => {"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}

  var request = BitcoinRequest(address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH");
  print(Bip21.encode(request));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

  var optionRequest = BitcoinRequest(
    address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH",
    options: {"amount": 20.3, "label": "Foo"},
  );
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foo

  optionRequest.amount = 50.0;
  optionRequest.label = "Bar";
  optionRequest.message = "Hello World";
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=50.0&label=Bar&message=Hello%20World

  var jsonDecoded = BitcoinRequest.fromJson(
    json.decode(
      '{"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}',
    ),
  );
  print(jsonDecoded.toString());
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?label=Foobar&amount=20.3
}

License #

This library is licensed under the MIT license. Please read the LICENSE file for more information.

1.0.0 #

  • Initial version

example/bip21_example.dart

import 'dart:convert';
import 'package:bip21/bip21.dart';

main() {
  var decoded = Bip21.decode(
      "bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foobar");
  print(decoded.toJson());
  // => {"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}

  var request = BitcoinRequest(address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH");
  print(Bip21.encode(request));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

  var optionRequest = BitcoinRequest(
    address: "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH",
    options: {"amount": 20.3, "label": "Foo"},
  );
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foo

  optionRequest.amount = 50.0;
  optionRequest.label = "Bar";
  optionRequest.message = "Hello World";
  print(Bip21.encode(optionRequest));
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=50.0&label=Bar&message=Hello%20World

  var jsonDecoded = BitcoinRequest.fromJson(
    json.decode(
      '{"address":"1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH","options":{"label":"Foobar","amount":20.3}}',
    ),
  );
  print(jsonDecoded.toString());
  // => bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?label=Foobar&amount=20.3
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bip21: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bip21/bip21.dart';
  
Version Uploaded Documentation Archive
1.0.0 Jan 17, 2019 Go to the documentation of bip21 1.0.0 Download bip21 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
92
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Apr 12, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:bip21/bip21.dart.

Health suggestions

Fix lib/src/bip21_base.dart. (-0.50 points)

Analysis of lib/src/bip21_base.dart reported 1 hint:

line 59 col 11: Use contains instead of indexOf

Maintenance suggestions

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
meta ^1.1.7 1.1.7
Dev dependencies
test ^1.0.0