Basic use of packages in iex

I’m follow this doc: Curvy — Curvy v0.3.0

so in my phx project I added this to my mix.exs {:curvy, "~> 0.3.0"}
then I did mix deps.get on the commandline
then I did iex on commandline
then I get this error:

iex(2)> Curvy.generate_key()
** (UndefinedFunctionError) function Curvy.generate_key/0 is undefined (module Curvy is not available)
    Curvy.generate_key()

How do I get the package at the iex level?

You need to iex -S mix to load your application and its dependencies into iex, alternatively you can use the following given your elixir version is new enough:

$ nix shell nixpkgs#elixir_1_12 -c iex
Erlang/OTP 24 [erts-12.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Interactive Elixir (1.12.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Mix.install([{:curvy, "~> 0.3.0"}])
Resolving Hex dependencies...
Dependency resolution completed:
New:
  curvy 0.3.0
* Getting curvy (Hex package)
==> curvy
Compiling 6 files (.ex)
Generated curvy app
:ok
iex(2)> Curvy.generate_key()
%Curvy.Key{
  compressed: true,
  crv: :secp256k1,
  point: %Curvy.Point{
    x: 49764956262856464511299791080151063488792754825564483844458065755946618593247,
    y: 17185691683386200067947373863573512678603614474885542177769521186371493393147
  },
  privkey: <<32, 235, 150, 173, 141, 17, 66, 253, 84, 17, 54, 53, 205, 85, 69,
    93, 75, 175, 50, 170, 14, 181, 50, 169, 106, 111, 157, 88, 94, 79, 210,
    128>>
}
3 Likes

you will want to run iex -S mix or iex -S mix phx.server (if running a phoenix application).

Edit: running iex will just run an elixir interactive shell, the commands above will start an interactive shell with your mix project as @NobbZ stated

4 Likes