Skip to content

DIOTA Library is a Delphi wrapper around IOTA (https://www.iota.org/) node's JSON-REST HTTP interface.

License

Notifications You must be signed in to change notification settings

lubovaskov/iota-delphi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IOTA Delphi client library

License IOTA IRI compatibility IOTA API coverage

This is an unofficial Delphi client library for IOTA, which allows you to do the following:

  • Create transactions
  • Sign transactions
  • Generate addresses
  • Interact with an IRI node

This is beta software, so there may be performance and stability issues. Please report any issues in our issue tracker.

Table of contents
Prerequisites
Setting up the library
Getting started
Supporting the project
License

Prerequisites

  • Delphi XE6 or newer

Setting up the library

  • Download and copy the diota folder to your projects folder.
  • Add the following paths to the Search path of your project:
diota\utils
diota\pow
diota\model
diota\libs\keccak
diota\dto\request
diota\dto\response

Getting Started

This example shows you how to create and send a transaction to an IRI node by calling the SendTransfer method.

uses
  System.Generics.Collections,
  DIOTA.IotaAPI,
  DIOTA.Utils.TrytesConverter,
  DIOTA.Model.Input,
  DIOTA.Model.Transfer,
  DIOTA.Dto.Response.SendTransferResponse,
  DIOTA.Dto.Response.GetBalancesAndFormatResponse;

var
  IotaAPI: IIotaAPI;
  Seed: String;
  Address: String;
  Value: Int64;
  TransactionMessage: String;
  Tag: String;
  Security: Integer;
  Depth: Integer;
  MinWeightMagnitude: Integer;
  RemainderAddress: String;
  Inputs: TList<IInput>;
  InputsRes: TGetBalancesAndFormatResponse;
  Transfers: TList<ITransfer>;
  Transfer: ITransfer;
  TransfersRes: TSendTransferResponse;  
  
begin
  IotaAPI := IotaAPIBuilder  // replace with your IRI node
    .Protocol('https')
    .Host('trinity.iota-tangle.io')
    .Port(14265)
    .Timeout(5000)
    .Build;

  // The seed must be truly random & 81-trytes long.
  Seed := '<SENDER SEED>';

  // Recipient address, must not have been spent from
  Address := '<RECIPIENT ADDRESS>';

  // An unspent sender address that will receive the remaining IOTAs, if any
  RemainderAddress := '<REMAINDER ADDRESS>';

  // Transaction value in IOTA, may be 0
  Value := 1;

  // Optional transaction message
  TransactionMessage := TTrytesConverter.AsciiToTrytes('DIOTA9MESSAGE');

  // Optional transaction tag
  Tag := 'DIOTA9TAG';

  //security level (1, 2 or 3)
  Security := 2;

  // Depth or how far to go for tip selection entry point
  Depth := 9;

  // Difficulty of Proof-of-Work required to attach the transaction to tangle.
  // Minimum value on mainnet & spamnet is `14`, `9` on devnet and other testnets.
  MinWeightMagnitude := 14;

  if Value > 0 then
    begin
      // Get a list of sender addresses to take IOTAs from
      InputsRes := IotaAPI.GetInputs(Seed, Security, 0, 10, Value, nil);
      try
        Inputs := InputsRes.InputsList;
      finally
        InputsRes.Free;
      end;
    end
  else
    Inputs := nil;

  // Create a new transfer to the recepient address using the supplied parameters
  Transfer := TTransferBuilder.CreateTransfer(Address, Value, TransactionMessage, Tag);

  // List of transfers which defines transaction recipients, value transferred in IOTAs and transaction messages
  Transfers := TList<ITransfer>.Create;
  try
    Transfers.Add(Transfer);
    // Prepare the bundle, sign and send it
    TransfersRes := IotaAPI.SendTransfer(Seed, Security, Depth, MinWeightMagnitude, Transfers, Inputs, RemainderAddress, True, True, nil);
    try
      if Assigned(TransfersRes) then
        ShowMessage('Successful transactions: ' + IntToStr(TransfersRes.SuccessfullyCount))
      else
        ShowMessage('Error sending transfers!');
    finally
      TransfersRes.Free;
    end;
  finally
    Transfers.Free;
    if Assigned(Inputs) then
      Inputs.Free;
  end;
end;

Supporting the project

If the IOTA Delphi client library has been useful to you and you feel like contributing, consider posting a bug report, feature request, pull request or a donation to address TGLRUQBV9QOCHYVXLRKMFMBURXOMXMJMBIWDZZNFKWLU9TGNNWH9AJM9K9BSKVDNFUA9LNTTCNODDICYXZZCJODNKC

License

The MIT license can be found here.

About

DIOTA Library is a Delphi wrapper around IOTA (https://www.iota.org/) node's JSON-REST HTTP interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published