Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Feature/predeployed accounts endpoint #138

Merged
merged 11 commits into from
Jun 24, 2022
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,25 @@ const account = await starknet.getAccountFromAddress(
);
```

The balance of an account can be checked using:
### Predeployed accounts can be checked using:
tabaktoni marked this conversation as resolved.
Show resolved Hide resolved

```
GET /get_predeployed_accounts
```

Response:

```
[{
tabaktoni marked this conversation as resolved.
Show resolved Hide resolved
"initial_balance": 1e+21,
"address": "0x7c3e2...",
"private_key": "0x6160...",
"public_key": "0x6a5540..."
},
...]
```

### The balance of an account can be checked using:

```
GET /account_balance?address=<HEX_ADDRESS>
Expand Down
9 changes: 9 additions & 0 deletions starknet_devnet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def get_contract_class(cls):
cls.CONTRACT_CLASS = ContractClass.load(load_nearby_contract(cls.CONTRACT_PATH))
return cls.CONTRACT_CLASS

def to_json(self):
"""Return json account"""
return {
"initial_balance": self.initial_balance,
FabijanC marked this conversation as resolved.
Show resolved Hide resolved
"private_key": hex(self.private_key),
"public_key": hex(self.public_key),
"address": hex(self.address)
}

async def deploy(self, starknet: Starknet) -> StarknetContract:
"""Deploy this account."""
account_carried_state = starknet.state.state.contract_states[self.address]
Expand Down
10 changes: 10 additions & 0 deletions starknet_devnet/blueprints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@ async def get_balance():
"amount": balance,
"unit": "wei"
})

@base.route("/get_predeployed_accounts", methods=["GET"])
FabijanC marked this conversation as resolved.
Show resolved Hide resolved
def get_predeployed_accounts():
"""Get predeployed accounts"""

accounts = state.starknet_wrapper.accounts
json_accounts = []
tabaktoni marked this conversation as resolved.
Show resolved Hide resolved
for account in accounts:
json_accounts.append(account.to_json())
return jsonify(json_accounts)