-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
knowledge-base.txt
5190 lines (3781 loc) · 183 KB
/
knowledge-base.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
######## ./docs\docs-readme.md
# Overview
**Ape Framework** is an easy-to-use Web3 development tool.
Users can compile, test, and interact with smart contracts all in one command line session.
With our **modular plugin system**, Ape supports multiple contract languages and chains.
Ape is built by [ApeWorX LTD](https://www.apeworx.io/).
Join our [ApeWorX Discord server](https://discord.gg/apeworx) to stay up to date on new releases, plugins and tutorials.
If you want to just get started, jump down to the [Playing with Ape](#playing-with-ape).
## Documentation
Read our [technical documentation](https://docs.apeworx.io/ape/stable/) to get a deeper understanding of our open source Framework.
Read our [academic platform](https://academy.apeworx.io/) will help you master Ape Framework with tutorials and challenges.
## Prerequisite
In the latest release, Ape requires:
- Linux or macOS
- Python 3.8 up to 3.11
- **Windows**: Install Windows Subsystem Linux [(WSL)](https://docs.microsoft.com/en-us/windows/wsl/install)
Check your python version in a terminal with `python3 --version`.
## Installation
There are three ways to install ape: `pipx`, `pip`, or `Docker`.
### Considerations for Installing:
- If using `pip`, we advise using the most up-to-date version of `pip` to increase the chance of a successful installation.
- See issue https://github.com/ApeWorX/ape/issues/1558.
- To upgrade `pip` from the command line, run: `pip install --upgrade pip`.
- We advise installing in a [virtualenv](https://pypi.org/project/virtualenv/) or [venv](https://docs.python.org/3/library/venv.html) to avoid interfering with *OS-level site packages*.
- We advise installing **`ape`** with recommended plugins `pip install eth-ape'[recommended-plugins]'`.
- We advise for **macOS** users to install virtual env via [homebrew](https://formulae.brew.sh/formula/virtualenv).
### via `pipx` or `pip`
1. Install `pipx` via their [installation instructions](https://pypa.github.io/pipx/) or `pip` via their [installation instructions](https://pip.pypa.io/en/stable/cli/pip_install/).
2. Install **`ape`** via `pipx install eth-ape` or `pip install eth-ape`.
### via `docker`
Ape can also run in a docker container.
Please visit our [Dockerhub](https://hub.docker.com/repository/docker/apeworx/ape) for more details on using Ape with Docker.
```bash
docker run \
--volume $HOME/.ape:/home/harambe/.ape \
--volume $HOME/.vvm:/home/harambe/.vvm \
--volume $HOME/.solcx:/home/harambe/.solcx \
--volume $PWD:/home/harambe/project \
apeworx/ape compile
```
## Playing with Ape
After you installed Ape, you can run `ape --version` to make sure it works and is the latest version.
There are two ways to interact with Ape:
- [CLI Reference](https://docs.apeworx.io/ape/latest/index.html)
- [Python Reference](https://docs.apeworx.io/ape/latest/index.html)
Ape is both a CLI tool and a Python SDK.
The CLI tool contains all the Ape commands and the Python SDK contains the classes and types needed to compose scripts, console actions, and tests.
## **Ape Modular Plugin System:**
Our [list of plugins](https://www.apeworx.io/#plugins) is the best way to have the most interoperable experience with Web3.
**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-party plugins.
Install 3rd party plugins at your own risk.
Additionally, plugins that come bundled with **`ape`** in the core installation cannot be removed and are part of the **`ape`** core software.
- Learn more about **installing** plugins from following this [installing user guide](https://docs.apeworx.io/ape/stable/userguides/installing_plugins.html).
- Learn more about **developing** your own plugins from this [developing user guide](https://docs.apeworx.io/ape/stable/userguides/developing_plugins.html).
### Accounts
In Ape, you will need accounts to make transactions.
You can import or generate accounts using the core `accounts` plugin:
```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
```
Learn more about accounts in Ape by following the [accounts guide](https://docs.apeworx.io/ape/stable/userguides/accounts.html).
### Plugins
Add any plugins you may need, such as `vyper`.
```bash
ape plugins list -a
ape plugins install vyper
ape plugins list -a
```
## Projects
When using Ape, you generally will work with a project.
Learn more about smart-contract **projects** from this [projects guide](https://docs.apeworx.io/ape/stable/userguides/projects.html).
### Compiling
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
```
Learn more about compiling in Ape by following the [compile guide](https://docs.apeworx.io/ape/stable/userguides/compile.html).
### Testing
Use Ape to test your smart-contract projects.
Provide the same arguments to `pytest` as you would to the `ape test` command.
For example:
```bash
ape test -k test_only_one_thing
```
Visit the [testing guide](https://docs.apeworx.io/ape/stable/userguides/testing.html) to learn more about testing using 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 ethereum:mainnet:infura
```
Visit [Ape Console](https://docs.apeworx.io/ape/stable/commands/console.html) to learn how to use Ape Console.
### Scripts
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
```
Learn more about scripting using Ape by following the [scripting guide](https://docs.apeworx.io/ape/stable/userguides/scripts.html).
### Logging
To enable debug logging, run your command with the `--verbosity` flag using `DEBUG` as the value:
```bash
ape --verbosity DEBUG run
```
### Networks
You can work with registered networks, providers, and blockchain ecosystems (like Ethereum):
```python
from ape import networks
with networks.ethereum.mainnet.use_provider("infura"):
... # Work with the infura provider here
```
To learn more about networks in Ape, see [this guide](https://docs.apeworx.io/ape/stable/commands/networks.html).
######## ./docs\docs-userguide-account.md
# Accounts
Accounts in Ape come from [AccountAPI](../methoddocs/api.html#ape.api.accounts.AccountAPI) implementations (e.g. from plugins).
There are typically two types of accounts:
1. Test accounts
2. Live network accounts
Test accounts are useful for local network testing and debugging contracts.
Live network accounts are for interacting with live blockchains and should be secured.
To learn more about Ethereum accounts, see [the Ethereum documentation](https://ethereum.org/en/developers/docs/accounts/).
## Test Accounts
Ape ships with pytest fixtures to assist in writing your tests.
Pre-funded test accounts are accessible via the [accounts fixture](./testing.html#accounts-fixture).
```python
def test_my_contract_method(accounts):
sender = accounts[0]
...
```
To access the same prefunded accounts in your scripts or console, use the root `accounts` object and the [test_accounts](../methoddocs/managers.html#ape.managers.accounts.AccountManager.test_accounts) property:
```python
from ape import accounts
sender = accounts.test_accounts[0]
```
You can configure your test accounts using your `ape-config.yaml` file:
```yaml
test:
mnemonic: test test test test test test test test test test test junk
number_of_accounts: 5
```
**WARN**: NEVER put a seed phrase with real funds here.
The accounts generated from this seed are solely for testing and debugging purposes.
You can create a new test account by doing the following:
```python
account = accounts.test_accounts.generate_test_account()
```
**NOTE**: Creating a new test account means it will be unfunded by default.
Learn more about test accounts from the [testing guide](./testing.html#accounts-fixture).
If your testing provider supports this feature, it is possible to directly set the balances of any address by performing the following action:
```python
account.balance += int(1e18) # Gives `account` 1 Ether
```
### Default Sender Support
In order to eliminate the usage of sender in contract calls, you can use `use_sender` context manager.
```python
with accounts.use_sender(0): # Use first account from test mnemonic
contract.myFunction(1)
with accounts.use_sender("<address>"): # Impersonate an account
contract.myFunction(1)
with accounts.use_sender(a): # a is a `TestAccountAPI` object
contract.myFunction(1)
```
## Live Network Accounts
When using live networks, you need to get your accounts into Ape.
Ape ships with a keyfile accounts plugin to assist with this.
All the available CLI commands for this accounts plugin can be found [here](../commands/accounts.html).
For example, you can [generate](../commands/accounts.html#accounts-generate) an account:
```bash
ape accounts generate <ALIAS>
```
Ape will prompt you for entropy which is used to increase randomness when creating your account.
Ape will then prompt you whether you want to show your mnemonic.
If you do not want to see your mnemonic you can select `n`.
Alternatively you can use the `--hide-mnemonic` option to skip the prompt.
```bash
ape accounts generate <ALIAS> --hide-mnemonic
```
If you elected to show your mnemonic Ape will then show you your newly generated mnemonic.
Ape will then prompt you for a passphrase which you will need to enter twice to confirm.
This passphrase is used to encrypt your account on disk, for extra security.
You will be prompted for it each time you load your account, so make sure to remember it.
After entering the passphrase Ape will then show you your new account address, HDPath, and account alias.
If you want to use a custom HDPath, use the `--hd-path` option:
```bash
ape accounts generate <ALIAS> --hd-path <HDPATH>
```
If you do not use the `--hd-path` option, Ape will use the default HDPath of (Ethereum network, first account).
If you want to use a custom mnemonic phrase word length, use the `--word-count` option:
```bash
ape accounts generate <ALIAS> --word-count <WORDCOUNT>
```
If you do not use the `--word-count` option, Ape will use the default word count of 12.
You can use all of these together or separately to control the way Ape creates and displays your account information.
If you already have an account and you wish to import it into Ape (say, from Metamask), you can use the [import command](../commands/accounts.html#accounts-import):
```bash
ape accounts import <ALIAS>
```
It will prompt you for the private key.
If you need help exporting your private key from Metamask, see [this guide](https://metamask.zendesk.com/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key).
You can also import accounts from mnemonic seed by using the `--use-mnemonic` flag:
```bash
ape accounts import <ALIAS> --use-mnemonic
```
It will then prompt you for the [mnemonic seed](https://en.bitcoin.it/wiki/Seed_phrase).
If you need help finding your mnemonic seed (Secret Recovery Phrase) in Metamask, see [this guide](https://metamask.zendesk.com/hc/en-us/articles/360015290032-How-to-reveal-your-Secret-Recovery-Phrase).
In addition, you can also use a custom HDPath by using the `--hd-path` option:
```bash
ape accounts import <ALIAS> --use-mnemonic --hd-path <HDPATH>
```
If you use the `--hd-path` option, you will need to pass the [HDPath](https://help.myetherwallet.com/en/articles/5867305-hd-wallets-and-derivation-paths) you'd like to use as an argument in the command.
If you do not use the `--hd-path` option, Ape will use the default HDPath of (Ethereum network, first account).
You can also [export](../commands/accounts.html#accounts-export) the private key of an account:
```bash
ape accounts export <ALIAS>
```
Ape will ask you for the password to the account and then give you the private key of that account.
You can then use that private key with [import](../commands/accounts.html#accounts-import).
You can alternatively load the private key into [Metamask wallet](https://metamask.zendesk.com/hc/en-us/articles/360015489331-How-to-import-an-account#h_01G01W07NV7Q94M7P1EBD5BYM4).
Then, in your scripts, you can [load](../methoddocs/managers.html#ape.managers.accounts.AccountManager.load) an account:
```python
from ape import accounts
account = accounts.load("<ALIAS>")
```
### Default Sender Support
In order to reduce repetition of adding `sender` in your contract calls, you can use `use_sender` context manager.
```python
with accounts.use_sender(0):
contract.myFunction(1)
with accounts.use_sender("<address>"):
contract.myFunction(1)
with accounts.use_sender("<alias>"):
contract.myFunction(1)
with accounts.use_sender(a): # a is a `AccountAPI` object
contract.myFunction(1)
```
## Automation
If you use your keyfile accounts in automation, such as CI/CD, you may need to programmatically unlock them and enable autosign.
**WARNING**: We don't recommend using this approach but it is possible due to sometimes being needed.
Ensure you are using a secure environment and are aware of what you are doing.
```python
from ape import accounts
from eth_account.messages import encode_defunct
account = accounts.load("<ALIAS>")
account.set_autosign(True, passphrase="<PASSPHRASE>")
# Now, you will not be prompted to sign messages or transactions
message = encode_defunct(text="Hello Apes!")
signature = account.sign_message(message)
```
## Keyfile Passphrase Environment Variable (more secure)
Another, more secure approach is to use an environment variable.
Set your passphrase in an environment variable by following this template:
```bash
export APE_ACCOUNTS_<alias>_PASSPHRASE="a"
```
Where `<alias>` is the name of the account you want to use.
Now, you can use your account to make any transactions without subsequently providing your passphrase.
```py
from ape import accounts
from eth_account.messages import encode_defunct
account = accounts.load("<ALIAS>")
account.set_autosign(True)
# Now, you will not be prompted to sign messages or transactions
message = encode_defunct(text="Hello Apes!")
signature = account.sign_message(message)
```
## Hardware Wallets
Because of the plugin system in Ape, we are able to support other types of accounts including hardware wallet accounts.
Check out these plugins:
- [ape-ledger](https://github.com/ApeWorX/ape-ledger)
- [ape-trezor](https://github.com/ApeWorX/ape-trezor)
To install one of these plugins, do the following:
```bash
ape plugins install ledger
```
######## ./docs\docs-userguide-clis.md
# CLIs
Ape uses the [click framework](https://click.palletsprojects.com/en/8.1.x/) for handling all CLI functionality.
There are CLIs found in a couple areas in the Ape framework:
1. Plugins
2. Scripts
Both plugins and scripts utilize `click` for their CLIs.
For plugins, CLIs are an option for extending the framework.
You can read more about plugin development and CLIs in the [developing plugins guide](./developing_plugins.html).
Scripts utilize CLIs as an option for users to develop their scripts.
You can read more about scripting and CLIs in the [scripting guide](./scripts.html).
This guide is for showcasing utilities that ship with Ape to assist in your CLI development endeavors.
## Ape Context Decorator
The `@ape_cli_context` gives you access to all the root Ape objects (`accounts`, `networks` etc.), the ape logger, and an `abort` method for stopping execution of your CLI gracefully.
Here is an example using all of those features from the `cli_ctx`:
```python
import click
from ape.cli import ape_cli_context
@click.command()
@ape_cli_context()
def cmd(cli_ctx):
cli_ctx.logger.info("Test")
account = cli_ctx.account_manager.load("metamask")
cli_ctx.abort(f"Bad account: {account.address}")
```
## Network Tools
The `@network_option()` allows you to select an ecosystem / network / provider combination.
When using with the `NetworkBoundCommand` cls, you can cause your CLI to connect before any of your code executes.
This is useful if your script or command requires a provider connection in order for it to run.
```python
import click
from ape import networks
from ape.cli import network_option, NetworkBoundCommand
@click.command()
@network_option()
def cmd(network):
# Choices like "ethereum" or "polygon:local:test".
click.echo(network)
@click.command(cls=NetworkBoundCommand)
@network_option()
def cmd(network):
# Fails if we are not connected.
click.echo(networks.provider.network.name)
```
## Account Tools
Use the `@account_option()` for adding an option to your CLIs to select an account.
This option does several things:
1. If you only have a single account in Ape (from both test accounts _and_ other accounts), it will use that account as the default.
(this case is rare, as most people have more than one test account by default).
2. If you have more than one account, it will prompt you to select the account to use.
3. You can pass in an account alias or index to the option flag to have it use that account.
4. It allows you to specify test accounts by using a choice of `TEST::{index_of_test_account}`.
Thus, if you use this option, no matter what, your script will have an account to use by the time the script starts.
Here is an example:
```python
import click
from ape.cli import account_option
@click.command()
@account_option()
def cmd(account):
# Will prompt the user to select an account if needed.
click.echo(account.alias)
```
And when invoking the command from the CLI, it would look like the following:
(where `<prefix>` is either `ape run` for scripts or `ape <custom-plugin-cmd>` for plugins)
```shell
<prefix> cmd # Use the default account.
<prefix> cmd --account 0 # Use first account that would show up in `get_user_selected_account()`.
<prefix> cmd --account metamask # Use account with alias "metamask".
<prefix> cmd --account TEST::0 # Use the test account at index 0.
```
Alternatively, you can call the `get_user_selected_account()` directly to have more control of when the account gets selected:
```python
import click
from ape.cli import get_user_selected_account
@click.command()
def cmd():
account = get_user_selected_account("Select an account to use")
click.echo(f"You selected {account.address}.")
```
Similarly, there are a couple custom arguments for aliases alone that are useful when making CLIs for account creation.
If you use `@existing_alias_argument()` and specify an alias does not already exist, it will error.
And visa-versa when using `@non_existing_alias_argument()`
```python
import click
from ape.cli import existing_alias_argument, non_existing_alias_argument
@click.command()
@existing_alias_argument()
def delete_account(alias):
# We know the alias is an existing account at this point.
click.echo(alias)
@click.command()
@non_existing_alias_argument()
def create_account(alias):
# We know the alias is not yet used in Ape at this point.
click.echo(alias)
```
######## ./docs\docs-userguide-compile.md
# Compile
Compile your project using the following command:
```bash
ape compile
```
Configure the location Ape looks for contracts by editing the `contracts_folder` key in your project's `ape-config.yaml` file:
```yaml
contracts_folder: src # Default is 'contracts/'
```
## The JSON Compiler
Ape ships with a compiler that is able to compile `.json` files.
This compiler is useful for the following:
1. **Interfaces**: If you know the address of an existing contract, you can include its ABI in your project and create a contract wrapper around it:
```python
from ape import project
# Comes from a file named `MyInterface.json` in the contracts/ folder.
my_interface = project.MyInterface
address = "0x1234556b5Ed9202110D7Ecd637A4581db8b9879F"
# Instantiate a deployed contract using the local interface.
contract = my_interface.at(address)
# Call a method named `my_method` found in the local contract ABI.
contract.my_method()
```
2. **Pre-existing Contract Types**: If you have a contract type JSON that was compiled elsewhere, you can include it in your project.
This is useful if you are unable or unwilling to install a compiler.
3. **Raw Compiler Output**: If you have an artifact with binary compiled elsewhere, you can include it in your project.
This is useful if you want to use contracts from much larger projects as dependency for your test cases.
**WARN**: You may have to adjust name and source ID similarly to raw contract-type output.
## Other Compiler Plugins
If your project includes Solidity (`.sol`) or Vyper (`.vy`) files, you will have to install additional compilers.
To include additional compilers in your project, you can add the plugins to the `plugins` list in your `ape-config.yaml` or install them using the CLI.
For information on how to configure plugins in your project, follow [this guide](./installing_plugins.html).
## Ignore Files
You can configure files to be ignored from compilation.
By default, Ape ignores files `package.json`, `package-lock.json`, `tsconfig.json`.
To override this list, edit your `ape-config.yaml` similarly:
```yaml
compiler:
ignore_files:
- "*package.json"
- "*package-lock.json"
- "*tsconfig.json"
- "*custom.json" # Append a custom ignore
```
**NOTE**: You must include the defaults in the list when overriding if you wish to retain them.
## Dependencies
In Ape, compiler plugins typically let you have dependencies.
See [this guide](./dependencies.html) to learn more about configuring dependencies in Ape.
To always compile dependencies in Ape during the `ape compile` command, use the CLI flag `--include-dependencies`:
```shell
ape compile --include-dependencies
```
Alternatively, configure it to always happen:
```yaml
compile:
use_dependencies: true
```
######## ./docs\docs-userguide-config.md
# Configure Ape
You can configure Ape using configuration files with the name `ape-config.yaml`.
There are two locations you can place an `ape-config.yaml` file.
1. In the root of your project
2. In your `$HOME/.ape` directory (global)
Project settings take precedent, but global settings allow you to configure preferences across all projects, such as your default mainnet provider (e.g. Alchemy versus running your own node).
This guide serves as an index of the settings you can include in any `ape-config.yaml` file.
## Contracts Folder
Specify a different path to your `contracts/` directory.
This is useful when using a different naming convention, such as `src/` rather than `contracts/`.
```yaml
contracts_folder: src
```
You can also use an absolute path.
This is useful for projects that compile contracts outside their directory.
```yaml
contracts_folder: "~/GlobalContracts"
```
## Default Ecosystem
You can change the default ecosystem by including the following:
```yaml
default_ecosystem: fantom
```
The default ecosystem is `ethereum`.
## Dependencies
Configure dependencies for your ape project.
To learn more about dependencies, see [this guide](./dependencies.html).
A simple example of configuring dependencies looks like this:
```yaml
dependencies:
- name: OpenZeppelin
github: OpenZeppelin/openzeppelin-contracts
version: 4.4.2
```
## Deployments
Share import deployments to public networks with your teammates:
```yaml
deployments:
ethereum:
mainnet:
- contract_type: MyContract
address: 0xc123aAacCcbBbaAa444777000111222111222111
ropsten:
- contract_type: MyContract
address: 0xc222000cCcbBbaAa444777000111222111222222
```
## Geth
When using the `geth` provider, you can customize its settings.
For example, to change the URI for an Ethereum network, do:
```yaml
geth:
ethereum:
mainnet:
uri: http://localhost:5030
```
## Networks
Set default network and network providers:
```yaml
ethereum:
default_network: mainnet-fork
mainnet_fork:
default_provider: hardhat
```
Set the gas limit for a given network:
```yaml
ethereum:
default_network: mainnet-fork
mainnet_fork:
gas_limit: max
```
You may use one of:
- `"auto"` - gas limit is estimated for each transaction
- `"max"` - the maximum block gas limit is used
- A number or numeric string, base 10 or 16 (e.g. `1234`, `"1234"`, `0x1234`, `"0x1234"`)
- An object with key `"auto"` for specifying an estimate-multiplier for transaction insurance
To use the auto-multiplier, make your config like this:
```yaml
ethereum:
mainnet:
gas_limit:
auto:
multiplier: 1.2 # Multiply 1.2 times the result of eth_estimateGas
```
For the local network configuration, the default is `"max"`. Otherwise, it is `"auto"`.
## Plugins
Set which `ape` plugins you want to always use.
**NOTE**: The `ape-` prefix is not needed and shouldn't be included here.
```yaml
plugins:
- name: solidity # ape-solidity plugin
version: 0.1.0b2
- name: ens
```
Install these plugins by running command:
```bash
ape plugins install
```
## Testing
Configure your test accounts:
```yaml
test:
mnemonic: test test test test test test test test test test test junk
number_of_accounts: 5
```
######## ./docs\docs-userguide-console.md
# Ape Console
Ape provides an [IPython](https://ipython.readthedocs.io/) interactive console with useful pre-defined locals to interact with your project.
```bash
ape console --network ethereum:mainnet
In [1]: chain.blocks.head.timestamp
Out[1]: 1647323479
```
WARNING: Contract changes are not reflected in the active console session.
If you need to make changes to your contract, you must re-start your console session for the compiler to handle the changes.
## Ape Namespace
Your console comes with pre-initialized root ape objects in your namespace.
| Name | Class |
| :--------: | :--------------------------------------------------------------------------------------------------------: |
| `accounts` | [AccountManager](../methoddocs/managers.html?highlight=accounts#module-ape.managers.accounts) |
| `networks` | [NetworkManager](../methoddocs/managers.html?highlight=networks#module-ape.managers.networks) |
| `chain` | [ChainManager](../methoddocs/managers.html?highlight=chain#module-ape.managers.chain) |
| `project` | [ProjectManager](../methoddocs/managers.html?highlight=project#module-ape.managers.project.manager) |
| `query` | [QueryManager](../methoddocs/managers.html?highlight=query#module-ape.managers.query) |
| `convert` | [convert](../methoddocs/managers.html?highlight=query#ape.managers.converters.AddressAPIConverter.convert) |
| `ape` | [ape](../methoddocs/ape.html) |
You can access them as if they are already initialized:
First, launch the console:
```bash
ape console
```
Then, type the name of the item and you will see its Python representation:
```python
In [1]: networks
Out[1]: <NetworkManager active_provider=<test chain_id=61>>
```
**NOTE**: To change the network of the active console, use the `--network` option.
Follow [this guide](./networks.html) for more information on networks in Ape.
## Namespace Extras
You can also create scripts to be included in the console namespace by adding a file (`ape_console_extras.py`) to your root project directory. All non-internal symbols from this file will be included in the console namespace. Internal symbols are prefixed by an underscore (`_`).
An example file might look something like this:
```python
from eth_utils import encode_hex, decode_hex
def latest(key):
return getattr(networks.active_provider.get_block("latest"), key)
```
Then both imported util functions and `WETH_ADDRESS` will be available when you launch the console.
```python
In [1]: latest('number')
Out[1]: 14388241
In [2]: encode_hex(latest('hash'))
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 set up an initialized Web3.py object by using one from an existing Ape Provider.
```python
def ape_init_extras(chain):
return {"web3": chain.provider._web3}
```
Then `web3` will be available to use immediately.
```python
In [1]: web3.eth.chain_id
Out[1]: 1
```
### Global Extras
You can also add an `ape_console_extras.py` file to the global ape data directory (`$HOME/.ape/ape_console_extras.py`) and it will execute regardless of what project context you are in. This may be useful for variables and utility functions you use across all of your projects.
## Configure
To automatically use other IPython extensions, add them to your `ape-config.yaml` file:
```yaml
console:
plugins:
# A plugin that lets you modify Python modules without having close/reopen your console.
- autoreload
```
## Magic Commands
The `ape-console` plugin ships with custom [magics](https://ipython.readthedocs.io/en/stable/interactive/magics.html#line-magics) that are available when running the `ape console` command or loading the `ape_console.plugin` IPython extension manually.
When starting an embedded console (from `-I` in `ape run` or `ape test`), you will have to load the extension manually.
To do this, run the following from _any_ `IPython` environment:
```shell
In [1]: %load_ext ape_console.plugin
```
Or add the `ape_console.plugin` extension to your `IPython` config.
Otherwise, when launching `ape console`, the magics are automatically available.
### %ape
The `%ape` magic invokes the CLI in your `ape-console` session:
```shell
In [1]: %ape
Usage: cli [OPTIONS] COMMAND [ARGS]...
Options:
-v, --verbosity LVL One of ERROR, WARNING, SUCCESS, INFO, or DEBUG
--version Show the version and exit.
--config Show configuration options (using `ape-config.yaml`)
-h, --help Show this message and exit.
Commands:
accounts Manage local accounts
cache Query from caching database
compile Compile select contract source files
console Load the console
init Initalize an ape project
networks Manage networks
plugins Manage ape plugins
run Run scripts from the `scripts/` folder
test Launches pytest and runs the tests for a project
Out[1]: <Result okay>
```
Run any CLI command this way without exiting your session.
### %bal
The `%bal` magic outputs a human-readable balance on an account, contract, address, or account alias.
```shell
In [1]: account = accounts.load("metamask0")
In [2]: %bal account
Out[2]: '0.00040634 ETH'
In [3]: %bal metamask0
Out[3]: '0.00040634 ETH'
In [4]: %bal 0xE3747e6341E0d3430e6Ea9e2346cdDCc2F8a4b5b
Out[4]: '0.00040634 ETH'
```
######## ./docs\docs-userguide-contracts.md
# Contracts
You can interact with contracts pythonically using ape!
First, we need to obtain a contract instance.
One way to do this is to deploy a contract.
The other way is to initialize an already-deployed contract using its address.
## From Deploy
Deploy contracts from your project using the `project` root-level object.
The names of your contracts are properties on the `project` object (e.g. `project.MyContract`) and their types are [ContractContainer](../methoddocs/contracts.html#ape.contracts.base.ContractContainer).
**NOTE**: To avoid naming collisions with other properties on the `project` object, you can also use the [get_contract()](../methoddocs/managers.html#ape.managers.project.manager.ProjectManager.get_contract) method to retrieve contract containers.