Skip to content

Latest commit

 

History

History
117 lines (78 loc) · 2.77 KB

README.md

File metadata and controls

117 lines (78 loc) · 2.77 KB

Hex pm GitHub Workflow Status Made by Five Binaries

blockfrost-erlang


Erlang SDK for Blockfrost.io API.

AboutGetting startedInstallationUsage


About

Erlang SDK for the Blockfrost.io API.

Getting started

To use this SDK, you first need to log in to blockfrost.io, create your project and retrieve the API token.


Installation

The SDK uses rebar3 for project management, hackney as its HTTP client and jsx for JSON parsing.

You can either work directly with this repository or add this package as a dependency of your project using

{deps, [
  {blockfrost_erlang, "1.0.0"}
  ]}

To enter a development shell, use nix-shell.

Usage

git clone https://github.com/blockfrost/blockfrost-erlang
cd blockfrost-erlang
nix-shell
rebar3 shell

If you export BLOCKFROST_TOKEN_PATH environment variable blockfrost-erlang will automatically load and configure network and token:

export BLOCKFROST_TOKEN_PATH=~/.blockfrost.mainnet.token

Then in eshell:

blockfrost:get_blocks_latest().

{ok, Block} = blockfrost:get_blocks_latest().
Hash = maps:get(<<"hash">>, Block).
TxCount = maps:get(<<"tx_count">>, Block).
io:format("Block ~p tx count: ~p~n", [binary:bin_to_list(Hash), TxCount]).

Alternatively you can use setup/1 function which accepts a project string, for example

blockfrost:setup("mainnet1A2B3C4D5E6F7G8H9I0J1K2L3M4N5O6P").

IPFS

Simple IPFS upload example of a raw string:

blockfrost:post_ipfs_add({multipart, [{<<"Filename">>, <<"Hello Erlang">>}]}).

See hackney documentation for more examples of multipart payload format.

Maintenance

Testing

Export a token

export BLOCKFROST_TOKEN_PATH=~/.blockfrost.mainnet.token

and run

rebar3 eunit

Typecheck

Run rebar3 dialyzer

Updating rebar-deps.nix

Run rebar3 nix lock