Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions antd-elixir/examples/02_data.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ Mix.install([
{:antd, path: ".."}
])

# Store and retrieve public immutable data
# Example 02: Store and retrieve public data, with cost estimation.
#
# Prerequisite: antd daemon running on local testnet.

client = Antd.Client.new()

# Store data
{:ok, result} = Antd.Client.data_put_public(client, "Hello, Autonomi!")
IO.puts("Stored at: #{result.address}")
IO.puts("Cost: #{result.cost} atto")
payload = "Hello, Autonomi!"

# Estimate cost before storing
{:ok, est} = Antd.Client.data_cost(client, payload)
IO.puts(
"Estimate: #{est.file_size} bytes in #{est.chunk_count} chunks, " <>
"storage #{est.cost} atto, gas #{est.estimated_gas_cost_wei} wei, " <>
"mode #{est.payment_mode}"
)

# Retrieve data
# Store public data
{:ok, result} = Antd.Client.data_put_public(client, payload)
IO.puts("Stored at address: #{result.address}")
IO.puts("Actual cost: #{result.cost} atto tokens")

# Retrieve it back
{:ok, data} = Antd.Client.data_get_public(client, result.address)
IO.puts("Retrieved: #{data}")

# Estimate cost before storing
{:ok, cost} = Antd.Client.data_cost(client, "Some data to estimate")
IO.puts("Estimated cost: #{cost} atto")
unless data == payload, do: raise "Round-trip mismatch!"
IO.puts("Public data round-trip OK!")
2 changes: 1 addition & 1 deletion antd-elixir/examples/04_files.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ IO.puts("Directory downloaded to /tmp/mydir_copy")

# Estimate file upload cost
{:ok, cost} = Antd.Client.file_cost(client, "/tmp/example.txt", true, false)
IO.puts("Estimated upload cost: #{cost} atto")
IO.puts("Estimated upload cost: #{cost.cost} atto (#{cost.chunk_count} chunks)")
2 changes: 1 addition & 1 deletion antd-elixir/examples/05_graph.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ IO.puts("Exists: #{exists}")

# Estimate cost
{:ok, cost} = Antd.Client.graph_entry_cost(client, "public_key_hex")
IO.puts("Estimated graph entry cost: #{cost} atto")
IO.puts("Estimated graph entry cost: #{cost.cost} atto (#{cost.chunk_count} chunks)")