0.0
The project is in a healthy, maintained state
A Ruby client for the Chainalysis API, allowing you to interact with Chainalysis's blockchain analysis tools.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 2.12
~> 2.9
 Project Readme

Chainalysis Ruby Client

A Ruby wrapper for the Chainalysis Transaction Monitoring API. This client library provides a simple, intuitive interface to interact with Chainalysis's API services.

Installation

Add this line to your application's Gemfile:

gem 'chainalysis'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install chainalysis

Usage

First, initialize a client with your API key:

require 'chainalysis'

client = Chainalysis::Client.new(api_key: 'your_api_key')

Registering a Transfer

# Register a new transfer
response = client.register_transfer(
  user_id: 'user123',
  network: 'Bitcoin',
  asset: 'BTC',
  transfer_reference: 'tx_hash:address',
  direction: 'received',
  # Optional parameters
  transfer_timestamp: '2024-01-10T15:30:00Z',
  asset_amount: 1.5,
  asset_price: 45000.00,
  asset_denomination: 'USD'
)

# The response includes an externalId that you can use to query the transfer
external_id = response['externalId']

Managing Transfers

# Get transfer details
transfer = client.get_transfer(external_id: 'transfer_external_id')

# Get transfer exposures
exposures = client.get_transfer_exposures(external_id: 'transfer_external_id')

# Get transfer alerts
alerts = client.get_transfer_alerts(external_id: 'transfer_external_id')

# Get transfer network identifications
identifications = client.get_transfer_network_identifications(external_id: 'transfer_external_id')

Managing Withdrawal Attempts

# Register a withdrawal attempt
response = client.register_withdrawal_attempt(
  user_id: 'user123',
  network: 'Bitcoin',
  asset: 'BTC',
  address: '1EM4e8eu2S2RQrbS8C6aYnunWpkAwQ8GtG',
  attempt_identifier: 'withdrawal_001',
  asset_amount: 2.5,
  attempt_timestamp: '2024-01-10T15:30:00Z'
)

# Get withdrawal attempt details
withdrawal = client.get_withdrawal_attempt(external_id: 'withdrawal_external_id')

# Get withdrawal attempt exposures
exposures = client.get_withdrawal_attempt_exposures(external_id: 'withdrawal_external_id')

# Get withdrawal attempt alerts
alerts = client.get_withdrawal_attempt_alerts(external_id: 'withdrawal_external_id')

# Get high risk addresses
addresses = client.get_withdrawal_attempt_high_risk_addresses(external_id: 'withdrawal_external_id')

# Get network identifications
identifications = client.get_withdrawal_attempt_network_identifications(external_id: 'withdrawal_external_id')

Categories and Administration

# Get all categories
categories = client.get_categories

# Get internal users (requires ORGADMIN permission)
users = client.get_internal_users

Error Handling

The client includes custom error classes for different types of API errors:

begin
  client.get_transfer(external_id: 'invalid_id')
rescue Chainalysis::NotFoundError => e
  puts "Transfer not found: #{e.message}"
rescue Chainalysis::AuthenticationError => e
  puts "Authentication failed: #{e.message}"
rescue Chainalysis::RateLimitError => e
  puts "Rate limit exceeded: #{e.message}"
rescue Chainalysis::BadRequestError => e
  puts "Bad request: #{e.message}"
rescue Chainalysis::ApiError => e
  puts "API error: #{e.message}"
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Running Tests

$ bundle exec rspec

Tests use VCR to record and replay HTTP interactions. To record new interactions, delete the corresponding cassette file and run the tests.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Chainalysis Ruby Client project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.