Module: MixinBot
- Defined in:
- lib/mixin_bot.rb,
lib/mixin_bot/api.rb,
lib/mixin_bot/cli.rb,
lib/mixin_bot/cli.rb,
lib/mixin_bot/nfo.rb,
lib/mixin_bot/uuid.rb,
lib/mixin_bot/utils.rb,
lib/mixin_bot/api/me.rb,
lib/mixin_bot/client.rb,
lib/mixin_bot/errors.rb,
lib/mixin_bot/address.rb,
lib/mixin_bot/api/app.rb,
lib/mixin_bot/api/pin.rb,
lib/mixin_bot/api/rpc.rb,
lib/mixin_bot/api/tip.rb,
lib/mixin_bot/cli/api.rb,
lib/mixin_bot/invoice.rb,
lib/mixin_bot/monitor.rb,
lib/mixin_bot/version.rb,
lib/mixin_bot/api/auth.rb,
lib/mixin_bot/api/code.rb,
lib/mixin_bot/api/fiat.rb,
lib/mixin_bot/api/turn.rb,
lib/mixin_bot/api/user.rb,
lib/mixin_bot/bot_auth.rb,
lib/mixin_bot/cli/base.rb,
lib/mixin_bot/cli/call.rb,
lib/mixin_bot/cli/node.rb,
lib/mixin_bot/computer.rb,
lib/mixin_bot/api/asset.rb,
lib/mixin_bot/api/blaze.rb,
lib/mixin_bot/api/chain.rb,
lib/mixin_bot/cli/utils.rb,
lib/mixin_bot/api/output.rb,
lib/mixin_bot/cli/errors.rb,
lib/mixin_bot/cli/output.rb,
lib/mixin_bot/cli/schema.rb,
lib/mixin_bot/url_scheme.rb,
lib/mixin_bot/api/address.rb,
lib/mixin_bot/api/deposit.rb,
lib/mixin_bot/api/message.rb,
lib/mixin_bot/api/network.rb,
lib/mixin_bot/api/payment.rb,
lib/mixin_bot/api/session.rb,
lib/mixin_bot/models/user.rb,
lib/mixin_bot/transaction.rb,
lib/mixin_bot/api/multisig.rb,
lib/mixin_bot/api/snapshot.rb,
lib/mixin_bot/api/transfer.rb,
lib/mixin_bot/api/withdraw.rb,
lib/mixin_bot/models/asset.rb,
lib/mixin_bot/utils/crypto.rb,
lib/mixin_bot/configuration.rb,
lib/mixin_bot/models/output.rb,
lib/mixin_bot/utils/address.rb,
lib/mixin_bot/utils/decoder.rb,
lib/mixin_bot/utils/encoder.rb,
lib/mixin_bot/api/attachment.rb,
lib/mixin_bot/models/address.rb,
lib/mixin_bot/api/inscription.rb,
lib/mixin_bot/api/legacy_user.rb,
lib/mixin_bot/api/pin_payload.rb,
lib/mixin_bot/api/transaction.rb,
lib/mixin_bot/api/computer_api.rb,
lib/mixin_bot/api/conversation.rb,
lib/mixin_bot/api/legacy_output.rb,
lib/mixin_bot/api/network_asset.rb,
lib/mixin_bot/models/ghost_keys.rb,
lib/mixin_bot/api/legacy_payment.rb,
lib/mixin_bot/cli/schema_command.rb,
lib/mixin_bot/transaction/buffer.rb,
lib/mixin_bot/api/legacy_multisig.rb,
lib/mixin_bot/api/legacy_snapshot.rb,
lib/mixin_bot/api/legacy_transfer.rb,
lib/mixin_bot/client/error_mapper.rb,
lib/mixin_bot/models/api_envelope.rb,
lib/mixin_bot/transaction/decoder.rb,
lib/mixin_bot/transaction/encoder.rb,
lib/mixin_bot/api/encrypted_message.rb,
lib/mixin_bot/api/legacy_collectible.rb,
lib/mixin_bot/api/legacy_transaction.rb,
lib/mixin_bot/models/safe_multisig_request.rb,
lib/mixin_bot/models/sequencer_transaction_request.rb
Overview
MixinBot
MixinBot is a Ruby SDK for interacting with the Mixin Network API.
Overview
Mixin Network is a free and lightning fast peer-to-peer transactional network for digital assets. MixinBot provides a comprehensive Ruby interface to interact with the Mixin Network, including asset management, transfers, messaging, and more.
Installation
Add this line to your application’s Gemfile:
gem 'mixin_bot'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install mixin_bot
Quick Start
Configuration
Configure your Mixin bot credentials:
MixinBot.configure do
self.app_id = '25696f85-b7b4-4509-8c3f-2684a8fc4a2a'
self.client_secret = 'd9dc58107bacde671...'
self.session_id = '25696f85-b7b4-4509-8c3f-2684a8fc4a2a'
self.server_public_key = 'b0pjBUKI0Vp9K+NspaL....'
self.session_private_key = '...'
end
Basic Usage
Get bot profile:
MixinBot.api.me
# => { "user_id" => "...", "full_name" => "...", ... }
Get bot assets:
MixinBot.api.assets
# => [{ "asset_id" => "...", "symbol" => "BTC", ... }, ...]
Transfer assets:
MixinBot.api.create_transfer(
'123456', # pin_code
asset_id: '965e5c6e-434c-3fa9-b780-c50f43cd955c', # CNB
opponent_id: '6ae1c7ae-1df1-498e-8f21-d48cb6d129b5', # receiver
amount: 0.00000001,
memo: 'test transfer',
trace_id: SecureRandom.uuid
)
Managing Multiple Bots
You can manage multiple bots by creating separate API instances:
bot1 = MixinBot::API.new(
app_id: '...',
session_id: '...',
session_private_key: '...',
server_public_key: '...'
)
bot2 = MixinBot::API.new(
app_id: '...',
session_id: '...',
session_private_key: '...',
server_public_key: '...'
)
bot1.me
bot2.me
Main Components
- MixinBot::API
-
Main API interface for interacting with Mixin Network
- MixinBot::Configuration
-
Configuration management for bot credentials
- MixinBot::Client
-
HTTP client for making API requests
- MixinBot::Utils
-
Utility methods for cryptography and encoding
- MixinBot::Transaction
-
Transaction encoding and decoding
- MixinBot::MixAddress
-
Address handling for Mixin Network
- MixinBot::Invoice
-
Invoice creation and parsing
- MixinBot::Nfo
-
NFT memo handling
- MixinBot::UUID
-
UUID utilities for Mixin Network
- MVM
-
Mixin Virtual Machine integration
Error Handling
MixinBot defines several custom error classes for different scenarios:
begin
MixinBot.api.create_transfer(...)
rescue MixinBot::InsufficientBalanceError => e
puts "Insufficient balance: #{e.message}"
rescue MixinBot::UnauthorizedError => e
puts "Unauthorized: #{e.message}"
rescue MixinBot::ResponseError => e
puts "API error: #{e.message}"
end
Links
Defined Under Namespace
Modules: CLIErrors, CLIHelpers, CLIOutput, CLISchema, Models, Monitor, UrlScheme, Utils Classes: API, ArgumentError, BotAuth, CLI, Client, Computer, Configuration, ConfigurationNotValidError, Error, ForbiddenError, HttpError, InsufficientBalanceError, InsufficientPoolError, InvalidInvoiceFormatError, InvalidNfoFormatError, InvalidTransactionFormatError, InvalidUuidFormatError, Invoice, InvoiceEntry, MainAddress, MixAddress, Nfo, NodeCLI, NotFoundError, PinError, RequestError, ResponseError, Transaction, UUID, UnauthorizedError, UserNotFoundError, UtilsCLI, UtxoInsufficientError
Constant Summary collapse
- MAIN_ADDRESS_PREFIX =
'XIN'- MIX_ADDRESS_PREFIX =
'MIX'- MIX_ADDRESS_VERSION =
2- UUID_ADDRESS_LENGTH =
16- MAIN_ADDRESS_LENGTH =
64- VERSION =
Current version of the MixinBot gem.
Follows Semantic Versioning (SemVer):
-
MAJOR version for incompatible API changes
-
MINOR version for backwards-compatible functionality additions
-
PATCH version for backwards-compatible bug fixes
-
'2.0.0'
Class Method Summary collapse
-
.api ⇒ MixinBot::API
Returns the default API instance using the global configuration.
-
.config ⇒ MixinBot::Configuration
Returns the global configuration instance.
-
.configure {|Configuration| ... } ⇒ void
Configures the global MixinBot settings.
-
.deprecator ⇒ ActiveSupport::Deprecation
ActiveSupport deprecation helper for legacy API surfaces.
-
.utils ⇒ Module
Returns the Utils module for accessing utility methods.
Class Method Details
.api ⇒ MixinBot::API
168 169 170 171 172 173 |
# File 'lib/mixin_bot.rb', line 168 def api return @api if defined?(@api) @api = MixinBot::API.new @api end |
.config ⇒ MixinBot::Configuration
Returns the global configuration instance.
The configuration instance stores bot credentials and settings. It will be created on first access with default values.
183 184 185 186 187 188 |
# File 'lib/mixin_bot.rb', line 183 def config return @config if defined?(@config) @config = MixinBot::Configuration.new @config end |
.configure {|Configuration| ... } ⇒ void
This method returns an undefined value.
Configures the global MixinBot settings.
This method yields the configuration instance to a block where you can set your bot credentials and other settings.
MixinBot.configure do
self.app_id = '25696f85-b7b4-4509-8c3f-2684a8fc4a2a'
self.session_id = '25696f85-b7b4-4509-8c3f-2684a8fc4a2a'
self.session_private_key = '...'
self.server_public_key = '...'
end
206 207 208 |
# File 'lib/mixin_bot.rb', line 206 def configure(&) config.instance_exec(&) end |
.deprecator ⇒ ActiveSupport::Deprecation
ActiveSupport deprecation helper for legacy API surfaces.
226 227 228 |
# File 'lib/mixin_bot.rb', line 226 def deprecator @deprecator ||= ActiveSupport::Deprecation.new('2.0', 'MixinBot') end |