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

Commit

Permalink
Remove invoke command (#227)
Browse files Browse the repository at this point in the history
* feat: remove invoke command and update README.md

* Update README.md

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>

* Update README.md

Co-authored-by: Martín Triay <martriay@gmail.com>

Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Martín Triay <martriay@gmail.com>
  • Loading branch information
3 people authored Oct 21, 2022
1 parent 981255d commit 22f219b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 54 deletions.
52 changes: 22 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,16 @@ You can find an example `.env` file in `example.env`. These are private keys onl
nile setup <private_key_alias>

🚀 Deploying Account
🌕 artifacts/Account.json successfully deployed to 0x07db6b52c8ab888183277bc6411c400136fe566c0eebfb96fffa559b2e60e794
⏳ ️Deployment of Account successfully sent at 0x07db6b52c8ab888183277bc6411c400136fe566c0eebfb96fffa559b2e60e794
🧾 Transaction hash: 0x17
📦 Registering deployment as account-0 in localhost.deployments.txt
Invoke transaction was sent.
Contract address: 0x07db6b52c8ab888183277bc6411c400136fe566c0eebfb96fffa559b2e60e794
Transaction hash: 0x17
```

A few things to notice here:
A few things to note here:

1. `nile setup <private_key_alias>` looks for an environment variable with the name of the private key alias
2. This creates a `localhost.accounts.json` file storing all data related to accounts management
2. This creates or updates `localhost.accounts.json` file storing all data related to accounts management
3. The creates or updates `localhost.deployments.txt` file storing all data related to deployments

### `send`

Expand All @@ -189,23 +188,15 @@ Some things to note:
- `max_fee` defaults to `0`. Add `--max_fee <max_fee>` to set the maximum fee for the transaction
- `network` defaults to the `localhost`. Add `--network <network>` to change the network for the transaction

### `call` and `invoke`
### `call`

Using `call` and `invoke`, we can perform read and write operations against our local node (or public one using the `--network mainnet` parameter). The syntax is:
Using `call`, we can perform read operations against our local node or the specified public network. The syntax is:

```sh
nile <command> <contract_identifier> <method> [PARAM_1, PARAM2...]
nile call <contract_identifier> <method> [PARAM_1, PARAM2...]
```

Where `<command>` is either `call` or `invoke` and `<contract_identifier>` is either our contract address or alias, as defined on `deploy`.

```sh
nile invoke my_contract increase_balance 1

Invoke transaction was sent.
Contract address: 0x07ec10eb0758f7b1bc5aed0d5b4d30db0ab3c087eba85d60858be46c1a5e4680
Transaction hash: 0x1
```
Where `<contract_identifier>` is either our contract address or alias, as defined on `deploy`.

```sh
nile call my_contract get_balance
Expand Down Expand Up @@ -239,17 +230,6 @@ Please note:

- `localhost` is the default network. Add `--network <network>` to change the network for the script

### `get_declaration` (NRE only)

Return the hash of a declared class. This can be useful in scenarios where a contract class is already declared with an alias prior to running a script.

```python
def run(nre):
predeclared_class = nre.get_declaration("alias")
```

> Note that this command is only available in the context of scripting in the Nile Runtime Environment.
### `clean`

Deletes the `artifacts/` directory for a fresh start ❄️
Expand Down Expand Up @@ -391,7 +371,7 @@ def run(nre):

> Please note that the list of accounts includes only those that exist in the local `<network>.accounts.json` file. In a recent release we added a flag to the command, to get predeployed accounts if the network you are connected to is a [starknet-devnet](https://github.com/Shard-Labs/starknet-devnet) instance.
### `get-accounts --predeployed`
### `get-accounts --predeployed (only starknet-devnet)`

This flag retrieves the predeployed accounts if the network you are connecting to is a [starknet-devnet](https://github.com/Shard-Labs/starknet-devnet) instance.

Expand Down Expand Up @@ -426,6 +406,18 @@ Retrieves the nonce for the given contract address (usually an account).
nile get-nonce <contract_address>
```

### `get_declaration` (NRE only)

Return the hash of a declared class. This can be useful in scenarios where a contract class is already declared with an alias prior to running a script.

```python
def run(nre):
predeclared_class = nre.get_declaration("alias")
```

> Note that this command is only available in the context of scripting in the Nile Runtime Environment.

## Short string literals

From [cairo-lang docs](https://www.cairo-lang.org/docs/how_cairo_works/consts.html#short-string-literals): A short string is a string whose length is at most 31 characters, and therefore can fit into a single field element.
Expand Down
19 changes: 1 addition & 18 deletions src/nile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def setup(signer, network):
@click.option("--max_fee", nargs=1)
@network_option
def send(signer, address_or_alias, method, params, network, max_fee=None):
"""Invoke a contract's method through an Account. Same usage as nile invoke."""
"""Invoke a contract's method through an Account."""
account = Account(signer, network)
print(
"Calling {} on {} with params: {}".format(
Expand All @@ -132,23 +132,6 @@ def send(signer, address_or_alias, method, params, network, max_fee=None):
print(out)


@cli.command()
@click.argument("address_or_alias", nargs=1)
@click.argument("method", nargs=1)
@click.argument("params", nargs=-1)
@click.option("--max_fee", nargs=1)
@network_option
def invoke(address_or_alias, method, params, network, max_fee=None):
"""Invoke functions of StarkNet smart contracts."""
if not is_alias(address_or_alias):
address_or_alias = normalize_number(address_or_alias)

out = call_or_invoke_command(
address_or_alias, "invoke", method, params, network, max_fee=max_fee
)
print(out)


@cli.command()
@click.argument("address_or_alias", nargs=1)
@click.argument("method", nargs=1)
Expand Down
6 changes: 0 additions & 6 deletions src/nile/nre.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ def call(self, address_or_alias, method, params=None):
call_or_invoke(address_or_alias, "call", method, params, self.network)
).split()

def invoke(self, address_or_alias, method, params=None):
"""Invoke a mutable function in a smart contract."""
if not is_alias(address_or_alias):
address_or_alias = normalize_number(address_or_alias)
return call_or_invoke(address_or_alias, "invoke", method, params, self.network)

def get_deployment(self, address_or_alias):
"""Get a deployment by its identifier (address or alias)."""
if not is_alias(address_or_alias):
Expand Down

0 comments on commit 22f219b

Please sign in to comment.