Skip to content

Commit

Permalink
feat: added more info to our quickstart to it make it more helpful (#633
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Ninjagod1251 authored Apr 14, 2022
1 parent 453b0a9 commit d85544e
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 399 deletions.
232 changes: 179 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,70 @@
# Ape Framework
# Quick Start

Ape is a framework for Web3 Python applications and smart contracts, with advanced functionality for testing, deployment, and on-chain interactions.
## Prerequisite

See [website](https://apeworx.io/) and [documentation](https://docs.apeworx.io/ape).
In the latest release, Ape requires:

## Dependencies
- Linux or macOS
- Python 3.7.X or later

* [python3](https://www.python.org/downloads) version 3.7 or greater, python3-dev
**Windows**:

1. Install Windows Subsystem Linux
[(WSL)](https://docs.microsoft.com/en-us/windows/wsl/install)
2. Choose Ubuntu 20.04 OR Any other Linux Distribution with Python
3.7.X or later

Please make sure you are using Python 3.7.X or later.

Check your python command by entering

```bash
python3 --version
```

## Installation

**Suggestion**: Create a virtual environment using `virtualenv` or `venv.`

You may skip this creating a virtual environment if you know you don\'t
require one for your use case.

* [virtualenv](https://pypi.org/project/virtualenv/)
* [venv](https://docs.python.org/3/library/venv.html)

Create your virtual environment folder

```bash
python3 -m venv /path/to/new/environment
source <venv_folder>/bin/activate
```

You should see `(name_of_venv) DESKTOP_NAME:~/path:$`.
To deactivate the virtual environment, do:

```bash
deactivate
```

Now that your Python version is later than 3.7.X and you have created a
virtual environment. Let\'s install Ape! There are 3 ways to install
ape: `pip`, `setuptools`, or `Docker`.

### via `pip`

You can install the latest release via [`pip`](https://pypi.org/project/pip/):
You can install the latest release via
[pip](https://pypi.org/project/pip/):

```bash
pip install -U pip
pip install eth-ape
```

### via `setuptools`

You can clone the repository and use [`setuptools`](https://github.com/pypa/setuptools) for the most up-to-date version:
You can clone the repository and use
[setuptools](https://github.com/pypa/setuptools) for the most up-to-date
version:

```bash
git clone https://github.com/ApeWorX/ape.git
Expand All @@ -30,12 +74,11 @@ python3 setup.py install

### via `docker`

Please visit our [Dockerhub](https://hub.docker.com/repository/docker/apeworx/ape) for more details on using Ape with Docker.
Please visit our
[Dockerhub](https://hub.docker.com/repository/docker/apeworx/ape) for
more details on using Ape with Docker.

example commands:

compiling:
```
```bash
docker run \
--volume $HOME/.ape:/root/.ape \
--volume $HOME/.vvm:/root/.vvm \
Expand All @@ -45,74 +88,157 @@ docker run \
apeworx/ape compile
```

running the ape console:
**Docker Uninstall Process:** You will need to remove files generated by
docker

```bash
sudo rm -rf **\~/.solcx**
sudo rm -rf **\~/.vvm**
```
docker run -it \
--volume $HOME/.ape:/root/.ape \
--volume $HOME/.vvm:/root/.vvm \
--volume $HOME/.solcx:/root/.solcx \
--volume $PWD:/root/project \
--workdir /root/project \
apeworx/ape console

## Overview

For more in-depth information about the project please look at the [projects](~/userguides/project.md)
It explains the purpose of each folder and how to use them effectively.

Use `ape init` to initialize your ape project folders. Visit [userguide project](~/userguide/project.md) for more information.

```bash
ape init
```

## Environment Variables:

Environment Variables are used to help connect you to your files or ecosystems outside of ApeWorX.

Please setup environment variables (where applicable) and follow the latest instructions from the 3rd party:

Example use case:

```bash
# Used by the `ape-infura` plugin
export WEB3_INFURA_PROJECT_ID=<YOUR_INFURA_PROJECT_ID>
# Used by the `ape-alchemy` plugin
export WEB3_ALCHEMY_API_KEY=<YOUR_ALCHEMY_KEY>
```

Visit [ape-alchemy](https://github.com/ApeWorX/ape-alchemy/blob/main/README.md#quick-usage)

Visit [ape-infura](https://github.com/ApeWorX/ape-infura#readme)

# Ape Console

Ape provides an IPython interactive console with useful pre-defined locals to interact with your project.
To interact with a deployed contract in a local environment, start by opening the console:

```bash
ape console --network :mainnet-fork:hardhat
```

Visit [Ape Console](https://docs.apeworx.io/ape/stable/commands/console.html) to learn how to use Ape Console.

## Quick Usage

Ape is primarily meant to be used as a command line tool. Here are some things you can use ape to do:
Use `-h` to list all the commands.

```bash
# Work with your accounts
$ ape accounts list
ape -h
```

You can import or generate accounts.

```bash
ape accounts import acc0 # Will prompt for a private key
ape accounts generate acc1
````

List all your accounts with the `list` command.

```bash
ape accounts list
```

Add any plugins you may need, such as `vyper`.

```bash
ape plugins list -a
ape plugins install vyper
ape plugins list -a
```

**NOTE**: If a plugin does not originate from the
[ApeWorX GitHub organization](https://github.com/ApeWorX?q=ape&type=all), you will get a warning about installing
3rd-class plugins. Any plugin that is not an official plugin has the chance of not being trustworthy. Thus, you should
be mindful about which plugins you install. Additionally, plugins that come bundled with `ape` in the core installation
cannot be removed and are considered part of the `ape` core software.

You can interact and compile contracts.
Here is an example of a project with a contract you interact with:

```bash
git clone https://github.com/brownie-mix/vyper-token-mix.git
cd vyper-token-mix/
```

You can compile contracts within the `contracts/` directory of your project.
The `--size` option will display you the size of the contract.

```bash
ape compile --size
```

Provide the same arguments to `pytest` as you would to the `ape test` command.

```bash
ape test -k test_only_one_thing --coverage
```

# Compile your project's smart contracts
$ ape compile --size
Connect an IPython session through your favorite provider.

# Run your tests with pytest
$ ape test -k test_only_one_thing --coverage --gas
```bash
ape console --network ethereum:mainnet:infura
```

If you want to run specific files in a `scripts/` directory, you can do it using the `ape run` command.

```bash
# This command will run a file named deploy in the scripts/ directory
$ ape run deploy
```

# Connect an IPython session through your favorite provider
$ ape console --network ethereum:mainnet:infura
### Logging

# Add new plugins to ape
$ ape plugins install plugin-name
To enable debug logging, run your command with the `--verbosity` flag using `DEBUG` as the value:

```bash
ape run --verbosity DEBUG
```

Ape also works as a package. You can use the same networks, accounts, and projects from the ape package as you can in the cli:
You can use `ape` as a package outside of scripts for the `ape run` command as well.

You can work with registered networks, providers, and blockchain ecosystems (like Ethereum):

```python
# Work with registered networks, providers, and blockchain ecosystems (like Ethereum)
from ape import networks
with networks.ethereum.mainnet.use_provider("infura"):
... # Work with the infura provider here
```

You can work with test accounts, local accounts, and (WIP) popular hardware wallets:

# Work with test accounts, local accounts, and (WIP) popular hardware wallets
```python
from ape import accounts
a = accounts[0] # Load by index
a = accounts.test_accounts[0] # Load test account by index
a = accounts["example.eth"] # or load by ENS/address
a = accounts.load("alias") # or load by alias
```

You can also work with contract types:

# Work with contract types
```python
from ape import project
c = a.deploy(project.MyContract, ...)
c.viewThis() # Make Web3 calls
c.doThat(sender=a) # Make Web3 transactions
assert c.MyEvent[-1].caller == a # Search through Web3 events
```

## Development

Please see the [contributing guide](CONTRIBUTING.md) to learn more how to contribute to this project.
Comments, questions, criticisms and pull requests are welcomed.

## Documentation

To build docs:

```bash
python build_docs.py
```

## License

This project is licensed under the [Apache 2.0](LICENSE).
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
userguides/config
userguides/transactions
userguides/console
userguides/testing
```

```{eval-rst}
Expand Down
2 changes: 1 addition & 1 deletion docs/userguides/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ Configure your test accounts:
test:
mnemonic: test test test test test test test test test test test junk
number_of_accounts: 5
```
```
2 changes: 1 addition & 1 deletion docs/userguides/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Out[2]: '0x68f768988e9bd4be971d527f72483f321975fa52aff9692b6d0e0af71fb77aaf'

### Init Function

If you include a function named `ape_init_extras`, it will be executed with the symbols from the existing namespace being provided as keyword arguments. This allows you to alter the scripts namespace using locals already included in the Ape namespace. If you return a `dict`, these values will be added to the console namespace. For example, you could setup an initialized Web3.py object by using one from an existing Ape Provider.
If you include a function named `ape_init_extras`, it will be executed with the symbols from the existing namespace being provided as keyword arguments. This allows you to alter the scripts namespace using locals already included in the Ape namespace. If you return a `dict`, these values will be added to the console namespace. For example, you could set up an initialized Web3.py object by using one from an existing Ape Provider.

```python
def ape_init_extras(chain):
Expand Down
Loading

0 comments on commit d85544e

Please sign in to comment.