Skip to content

Commit ae9c597

Browse files
author
Matthias Zimmermann
committed
simplify Arkiv client creation for prototyping
1 parent 588fa62 commit ae9c597

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Arkiv SDK
22

3-
Arkiv is a permissioned storage system for decentralized apps, supporting flexible entities with binary data, annotations, and metadata.
3+
Arkiv is ## Hello World
4+
Here's a "Hello World!" example showing how to use the Python Arkiv SDK:
5+
6+
```python
7+
from arkiv import Arkiv
8+
9+
# Create an Arkiv client for prototyping.
10+
# The default setup creates a funded default account and starts a containerized Arkiv node.
11+
client = Arkiv()
12+
print(f"Connected: {client.is_connected()}")ned storage system for decentralized apps, supporting flexible entities with binary data, annotations, and metadata.
413

514
The Arkiv SDK is the official Python library for interacting with Arkiv networks. It offers a type-safe, developer-friendly API for managing entities, querying data, subscribing to events, and offchain verification—ideal for both rapid prototyping and production use.
615

@@ -25,12 +34,14 @@ Here's a "Hello World!" example showing how to use the Python Arkiv SDK:
2534

2635
```python
2736
from arkiv import Arkiv
28-
from arkiv.account import NamedAccount
2937

30-
# Create account and client that implicitly starts a local Arkiv node
31-
alice = NamedAccount.create('Alice')
32-
client = Arkiv(account=alice)
33-
print(f"Connected: {client.is_connected()}")
38+
# Create Arkiv client with default settings:
39+
# - starting and connecting to a containerized Arkiv node
40+
# - creating a funded default account
41+
client = Arkiv()
42+
print(f"Client: {client}, connected: {client.is_connected()}")
43+
print(f"Account: {client.eth.default_account}")
44+
print(f"Balance: {client.from_wei(client.eth.get_balance(client.eth.default_account), 'ether')} ETH")
3445

3546
# Create entity with data and annotations
3647
entity_key, tx_hash = client.arkiv.create_entity(
@@ -66,10 +77,14 @@ tx = client.eth.get_transaction(tx_hash)
6677
### Arkiv Module Extension
6778
```python
6879
from arkiv import Arkiv
69-
from arkiv.account import NamedAccount
7080

81+
# Simple local setup
82+
client = Arkiv()
83+
84+
# Or with custom provider and account
85+
from arkiv.account import NamedAccount
7186
account = NamedAccount.from_wallet('Alice', wallet, 's3cret')
72-
client = Arkiv(provider, account = account)
87+
client = Arkiv(provider, account=account)
7388

7489
entity_key, tx_hash = client.arkiv.create_entity(
7590
payload=b"Hello World!",

USE_CASES.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,10 @@ arkiv.create_entity(metadata, annotations={"token_id": token_id})
453453

454454
```python
455455
from arkiv import Arkiv
456-
from arkiv.account import NamedAccount
457456

458-
# Connect to Arkiv
459-
alice = NamedAccount.create('Alice')
460-
client = Arkiv(account=alice)
457+
# Create an Arkiv client for prototyping.
458+
# The default setup creates a funded default account and starts a containerized Arkiv node.
459+
client = Arkiv()
461460

462461
# Start building
463462
entity_key, tx_hash = client.arkiv.create_entity(

src/arkiv/client.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,32 @@ def __init__(
3838
) -> None:
3939
"""Initialize Arkiv client with Web3 provider.
4040
41-
If no Web3 provider is provided, a local development node is automatically created and started.
41+
If no Web3 provider is provided, a local development node is automatically created and started
42+
with a funded default account for rapid prototyping.
4243
Remember to call arkiv.node.stop() for cleanup, or use context manager:
4344
4445
Examples:
45-
Auto-managed local node:
46+
Simplest setup (auto-managed node + default account):
4647
>>> with Arkiv() as arkiv:
48+
... # Default account created, funded with test ETH
49+
... print(arkiv.eth.default_account)
4750
... print(arkiv.eth.chain_id)
4851
49-
With account (auto-funded on local node):
52+
With custom account (auto-funded on local node):
5053
>>> account = NamedAccount.create("alice")
5154
>>> with Arkiv(account=account) as arkiv:
5255
... balance = arkiv.eth.get_balance(account.address)
5356
54-
Custom provider:
57+
Custom provider (no auto-node or account):
5558
>>> provider = ProviderBuilder().kaolin().build()
56-
>>> arkiv = Arkiv(provider) # No auto-node
59+
>>> account = NamedAccount.from_wallet("alice", wallet_json, password)
60+
>>> arkiv = Arkiv(provider, account=account)
5761
5862
Args:
5963
provider: Web3 provider instance (e.g., HTTPProvider).
60-
If None, creates local ArkivNode (requires Docker and testcontainers).
64+
If None, creates local ArkivNode with default account (requires Docker and testcontainers).
6165
account: Optional NamedAccount to use as the default signer.
66+
If None and provider is None, creates 'default' account.
6267
Auto-funded with test ETH if using local node and balance is zero.
6368
**kwargs: Additional arguments passed to Web3 constructor
6469
@@ -77,6 +82,13 @@ def __init__(
7782

7883
provider = ProviderBuilder().node(self.node).build()
7984

85+
# Create default account if none provided (for local node prototyping)
86+
if account is None:
87+
logger.info(
88+
f"Creating default account '{self.ACCOUNT_NAME_DEFAULT}' for local node..."
89+
)
90+
account = NamedAccount.create(self.ACCOUNT_NAME_DEFAULT)
91+
8092
super().__init__(provider, **kwargs)
8193

8294
# Initialize entity management module

tests/test_arkiv_create.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@ class TestArkivClientCreation:
2020
"""Test various Arkiv client creation scenarios."""
2121

2222
def test_create_arkiv_without_provider(self) -> None:
23-
"""Test creating Arkiv client without provider."""
23+
"""Test creating Arkiv client without provider (creates local node + default account)."""
2424
with Arkiv() as client:
25-
_assert_arkiv_client_properties(client, None, "Without Provider")
26-
logger.info("Created Arkiv client without provider")
25+
# When no provider given, Arkiv creates a local node AND a default account
26+
assert client.node is not None, "Should create managed node"
27+
assert len(client.accounts) == 1, "Should create default account"
28+
assert "default" in client.accounts, "Should have 'default' account"
29+
assert client.current_signer == "default", (
30+
"Should set default as current signer"
31+
)
32+
assert client.eth.default_account is not None, (
33+
"Should have default account set"
34+
)
35+
assert client.is_connected(), "Should be connected to managed node"
36+
logger.info(
37+
"Created Arkiv client without provider - auto-created node and default account"
38+
)
2739

2840
def test_create_arkiv_with_http_provider(self, arkiv_node) -> None:
2941
"""Test creating Arkiv client with HTTP provider."""

0 commit comments

Comments
 (0)