viz_transaction 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

viz-transaction #

GitHub Build Status

Using this library you can easily create and sign transactions for VIZ blockchain. It also allows you to multi-sign existing transactions or create them without signature at all.

NOTE: You cannot broadcast transactions to the blockchain using this library. Only serialization and signing. To send transactions to the network, use any other http/ws-library

Example transfer #

Signing transfer operations with viz-transaction is very simple:

import 'package:viz_transaction/viz_transaction.dart';

void main() {
  Transaction trx = Transaction();
  trx.refBlockNum = 46179;
  trx.refBlockPrefix = 1490075988;

  Transfer transfer = Transfer(
      from: AccountName('<SENDER_LOGIN>'),
      to: AccountName('<RECEIVER_LOGIN>'),
      amount: VizAsset.fromString('1.000 VIZ'),
      memo: Memo('Hello world!'));

  trx.operations.add(transfer);
  trx.sign(['<ACTIVE_PRIVATE_KEY>']); //Sign transaction

  // And get a json string to broadcast in blockchain
  print(trx.toJsonString());
}

Example award #

What about creating and signing a transaction with an award operation? Let's do it without beneficiaries.

import 'package:viz_transaction/viz_transaction.dart';

void main() {
  Transaction trx = Transaction(
      refBlockNum: 46179,
      refBlockPrefix: 1490075988);

  Award award = Award(
      initiator: AccountName('<INITIATOR_LOGIN>'),
      receiver: AccountName('<RECEIVER_LOGIN>'),
      energy: 1000, // 10.00%
      memo: Memo('Hello World'));

  trx.operations.add(award);
  trx.sign(['<REGULAR_PRIVATE_KEY>']); //Sign transaction

  print(trx.toJsonString()); // And get a json string to broadcast in blockchain
}

And now let's do the same but with two beneficiaries.

import 'package:viz_transaction/viz_transaction.dart';

void main() {
  Transaction trx = Transaction();
  trx.refBlockNum = 46179;
  trx.refBlockPrefix = 1490075988;

  Award award = Award();
  award.initiator = AccountName('<INITIATOR_LOGIN>');
  award.receiver = AccountName('<RECEIVER_LOGIN>');
  award.energy = 1000; // 10.00%
  award.memo = Memo('Hello World');
  award.beneficiaries = [
    BeneficiaryRouteType(AccountName('<BENEFICIARY_ONE>'),
        50), // Share 0.50% with BENEFICIARY_ONE
    BeneficiaryRouteType(AccountName('<BENEFICIARY_TWO>'),
        50) // Share 0.50% with BENEFICIARY_TWO
  ];

  trx.operations.add(award);
  trx.sign(['<REGULAR_PRIVATE_KEY>']); //Sign transaction

  // And get a json string to broadcast in blockchain
  print(trx.toJsonString());
}

As you may have noticed, an empty constructor was used for "award" operation, and then values were set. Just because it is possible.

Example gets ref block num and prefix #

As you can see, we set refBlockNum and refBlockPrefix manually, but in any case you need to get them from the block number (height) and block identifier respectively. Fortunately, you can do this by simply calling the utils methods, as demonstrated below:

int refBlockNum = BlockchainUtils.getRefBlockNum(7097393);
int refBlockPrefix = BlockchainUtils.getRefBlockPrefix("006c4c314a0c19918caa3187abdebfeeb56724b1");

See more examples in the example folder.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

  • Initial version, created by Stagehand

example/example.md

Example transfer #

Signing transfer operations with viz-transaction is very simple:

import 'package:viz_transaction/viz_transaction.dart';

void main() {
  Transaction trx = Transaction();
  trx.refBlockNum = 46179;
  trx.refBlockPrefix = 1490075988;

  Transfer transfer = Transfer(
      from: AccountName('<SENDER_LOGIN>'),
      to: AccountName('<RECEIVER_LOGIN>'),
      amount: VizAsset.fromString('1.000 VIZ'),
      memo: Memo('Hello world!'));

  trx.operations.add(transfer);
  trx.sign(['<ACTIVE_PRIVATE_KEY>']); //Sign transaction

  // And get a json string to broadcast in blockchain
  print(trx.toJsonString());
}

Example award #

What about creating and signing a transaction with an award operation? Let's do it without beneficiaries.

import 'package:viz_transaction/viz_transaction.dart';

void main() {
  Transaction trx = Transaction(
      refBlockNum: 46179,
      refBlockPrefix: 1490075988);

  Award award = Award(
      initiator: AccountName('<INITIATOR_LOGIN>'),
      receiver: AccountName('<RECEIVER_LOGIN>'),
      energy: 1000, // 10.00%
      memo: Memo('Hello World'));

  trx.operations.add(award);
  trx.sign(['<REGULAR_PRIVATE_KEY>']); //Sign transaction

  print(trx.toJsonString()); // And get a json string to broadcast in blockchain
}

And now let's do the same but with two beneficiaries.

import 'package:viz_transaction/viz_transaction.dart';

void main() {
  Transaction trx = Transaction();
  trx.refBlockNum = 46179;
  trx.refBlockPrefix = 1490075988;

  Award award = Award();
  award.initiator = AccountName('<INITIATOR_LOGIN>');
  award.receiver = AccountName('<RECEIVER_LOGIN>');
  award.energy = 1000; // 10.00%
  award.memo = Memo('Hello World');
  award.beneficiaries = [
    BeneficiaryRouteType(AccountName('<BENEFICIARY_ONE>'),
        50), // Share 0.50% with BENEFICIARY_ONE
    BeneficiaryRouteType(AccountName('<BENEFICIARY_TWO>'),
        50) // Share 0.50% with BENEFICIARY_TWO
  ];

  trx.operations.add(award);
  trx.sign(['<REGULAR_PRIVATE_KEY>']); //Sign transaction

  // And get a json string to broadcast in blockchain
  print(trx.toJsonString());
}

As you may have noticed, an empty constructor was used for "award" operation, and then values were set. Just because it is possible.

Example gets ref block num and prefix #

As you can see, we set refBlockNum and refBlockPrefix manually, but in any case you need to get them from the block number (height) and block identifier respectively. Fortunately, you can do this by simply calling the utils methods, as demonstrated below:

int refBlockNum = BlockchainUtils.getRefBlockNum(7097393);
int refBlockPrefix = BlockchainUtils.getRefBlockPrefix("006c4c314a0c19918caa3187abdebfeeb56724b1");

Example withdraw vesting operation #

import 'package:viz_transaction/viz_transaction.dart';

void main() {
  Transaction trx = Transaction();
  trx.refBlockNum = 46179;
  trx.refBlockPrefix = 1490075988;

  WithdrawVesting withdraw = WithdrawVesting(
      account: AccountName('<ACCOUNT_NAME>'),
      amount: SharesAsset.fromString('1.000000 SHARES')
      );

  trx.operations.add(withdraw);
  trx.sign(['<ACTIVE_PRIVATE_KEY>']); //Sign transaction

  // And get a json string to broadcast in blockchain
  print(trx.toJsonString());
}

See more examples in the example/lib folder.

Use this package as a library

1. Depend on it

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


dependencies:
  viz_transaction: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:viz_transaction/viz_transaction.dart';
  
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]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.1 <3.0.0
buffer ^1.0.6 1.0.6
convert ^2.1.1 2.1.1
viz_dart_ecc ^1.0.1 1.0.1+1
Transitive dependencies
base58check 1.0.1
charcode 1.1.2
collection 1.14.12
crypto 2.1.3
pointycastle 1.0.1
typed_data 1.1.6
Dev dependencies
pedantic ^1.0.0
test ^1.0.0