An Elixir library for reading Solidity ABI JSON files and turning them into Elixir modules with proper documentation on each method, built on top of the Fireblocks SDK.
Installation
Add fireblocks_contract to your list of dependencies in mix.exs:
def deps do
[
{:fireblocks_contract, "~> 0.1"},
{:fireblocks_sdk, "~> 0.2"}
]
endUsage
1. Define a contract module
Point use Fireblocks.Evm.Contract at your ABI file:
defmodule MyApp.Contracts.ERC20 do
use Fireblocks.Evm.Contract,
abi_file: "priv/abi/erc20.json"
endYou can also supply a default deployed address and a default Fireblocks base asset ID so you don't have to repeat them on every call:
defmodule MyApp.Contracts.ERC20 do
use Fireblocks.Evm.Contract,
abi_file: "priv/abi/erc20.json",
default_address: "0xA0b8...FeAb",
default_base_asset_id: "ETH"
end2. Reading contract state
Every ABI function becomes a snake_cased Elixir function that returns an
%Fireblocks.Evm.Contract.Call{} struct. Pipe it into Fireblocks.Evm.Contract.read/2:
# Read the token name
MyApp.Contracts.ERC20.name()
|> Fireblocks.Evm.Contract.read(
baseAssetId: "ETH",
contractAddress: "0xA0b8...FeAb"
)
# {:ok, ["My Token"]}
# Read a token balance
MyApp.Contracts.ERC20.balance_of("0x...")
|> Fireblocks.Evm.Contract.read(
baseAssetId: "ETH",
contractAddress: "0xA0b8...FeAb"
)
# {:ok, [raw_balance]}3. Writing contract state
Use Fireblocks.Evm.Contract.write/2 for state-changing functions. The call is
executed as a Fireblocks on-chain transaction and returns a transaction ID:
MyApp.Contracts.ERC20.transfer("0xDest...", 1_000_000)
|> Fireblocks.Evm.Contract.write(
baseAssetId: "ETH",
contractAddress: "0xA0b8...FeAb",
vaultAccountId: "1",
feeLevel: :medium,
note: "monthly distribution",
useGasless: false
)
# {:ok, %{"txId" => "4514c3e5-6520-400d-8980-1a1b940a0cb0"}}License
MIT