Skip to content

Commit c343367

Browse files
emizzleiurimatias
authored andcommitted
chore(@embark/vyper): Update README for Vyper plugin
See the associated PR embarklabs/blog#18.
1 parent 533a2e3 commit c343367

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

packages/plugins/vyper/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,124 @@
22

33
> Embark wrapper for the Vyper compiler
44
5+
## Step 1. Install the Embark Vyper plugin
6+
Installing the [Embark Vyper](https://github.com/embarklabs/embark/blob/master/packages/plugins/vyper/README.md) plugin in our ÐApp is extremely simple:
7+
1. Add the `embark-vyper` package to your ÐApp:
8+
```
9+
yarn add embark-vyper
10+
# OR
11+
npm i embark-vyper
12+
```
13+
2. Add the `embark-vyper` plugin to `embark.json`:
14+
```
15+
// embark.json
16+
17+
// ...
18+
"plugins": {
19+
"embark-ipfs": {},
20+
"embark-swarm": {},
21+
"embark-whisper-geth": {},
22+
"embark-geth": {},
23+
"embark-parity": {},
24+
"embark-profiler": {},
25+
"embark-graph": {},
26+
"embark-vyper": {} // <====== add this!
27+
},
28+
// ...
29+
```
30+
31+
## Step 2. Add a Vyper contract to your &ETH;App
32+
For the purposes of this guide, let's delete the existing `SimpleStorage` Solidity contract that comes with the Embark Demo by default if it exists:
33+
```
34+
rm -rf contracts/simple_storage.sol
35+
```
36+
Next, let's create a Vyper contract in the `contracts` folder of our &ETH;App, ie `contract/SimpleStorage.vy` (case is important):
37+
```
38+
# contracts/SimpleStorage.vy
39+
40+
storedData: public(int128)
41+
42+
@public
43+
def __init__(_x: int128):
44+
self.storedData = _x
45+
46+
@public
47+
def set(_x: int128):
48+
self.storedData = _x
49+
```
50+
The function of this contract is simple: upon creation (deployment), it will store the value we initially give it during deployment. We also have access to a `set()` that will allow to set the value stored in the contract.
51+
52+
### Changing the contract filename
53+
Because Vyper's constructor is called `__init__`, Embark must take the contract class name from the file name. If you'd prefer to change the name of your contract file to something else like `contracts/simple_storage.vy`, you'll need to update `config/contract.js` to allow Embark to match a contract configuration to a contract file:
54+
```
55+
// config/contracts.js
56+
57+
module.exports = {
58+
default: {
59+
// ...
60+
deploy: {
61+
simple_storage: {
62+
fromIndex: 0,
63+
args: [100]
64+
}
65+
}
66+
// ...
67+
}
68+
}
69+
```
70+
Please see the Embark [smart contract configuration documentation](https://framework.embarklabs.io/docs/contracts_configuration.html) for more information on how to configure contracts in Embark.
71+
72+
## Step 3. Run Embark
73+
Now that we have installed and configured everything, let's run Embark and watch the magic!
74+
```
75+
embark run --nodashboard --nobrowser
76+
```
77+
Assuming we kept the file name `SimpleStorage.vy` from step 4, we should see the following output in the console:
78+
```
79+
compiling Vyper contracts...
80+
deploying contracts
81+
Deploying SimpleStorage with 144379 gas at the price of 2000000000 Wei. Estimated cost: 288758000000000 Wei (txHash: 0x370a864b12b1785b17180b2a10ec2f941a15638eeffadfecf5bbe68755a06f14)
82+
SimpleStorage deployed at 0x5Baf4D88bC454537C51CEC7568a1E23400483abc using 135456 gas (txHash: 0x370a864b12b1785b17180b2a10ec2f941a15638eeffadfecf5bbe68755a06f14)
83+
```
84+
85+
### Troubleshooting
86+
There are a few common issues you may experience when Embark attempts to compile and deploy your Vyper contracts.
87+
88+
#### Vyper is not installed on your machine
89+
```
90+
Vyper is not installed on your machine
91+
You can install it by visiting: https://vyper.readthedocs.io/en/latest/installing-vyper.html
92+
```
93+
This means that the binary `vyper` cannot be found on your machine. If you're running *nix, you can verify this by running:
94+
```
95+
which vyper
96+
# expected output: path/to/virtual-env/bin/vyper
97+
# actual output: vyper not found
98+
```
99+
If `vyper` was [installed in a virtual environment](https://vyper.readthedocs.io/en/latest/installing-vyper.html#creating-a-virtual-environment), you may have forgotten to active the environment, ie:
100+
```
101+
source path/to/vyper-env/bin/activate
102+
```
103+
If `vyper` was not installed in a virual environment, it means either your `PATH` environment variable needs to be updated to point to the directory where the `vyper` binary is installed. You can inspect your `PATH` environment variable by:
104+
```
105+
echo $PATH
106+
```
107+
And update it with the path to *the directory containing* the `vyper` binary using:
108+
```
109+
export PATH=/path/to/vyper/dir:$PATH
110+
```
111+
112+
#### Error deploying contract
113+
```
114+
SimpleStorage has no code associated
115+
did you mean "simple_storage"?
116+
deploying contracts
117+
Error deploying contract simple_storage
118+
[simple_storage]: Invalid number of parameters for "constructor". Got 0 expected 1!
119+
Error deploying contracts. Please fix errors to continue.
120+
```
121+
This means that the contract `simple_storage` is a file in `contracts/` and expected to be deployed by Embark, but is not configured for deploy in the contracts configuration. This could be the result of changing the filename of the Vyper contract to `simple_storage.vy`, but not updating the contracts configuration, as outlined in [step 2](#Changing-the-contract-filename).
122+
123+
5124
Visit [framework.embarklabs.io](https://framework.embarklabs.io/) to get started with
6125
[Embark](https://github.com/embarklabs/embark).

0 commit comments

Comments
 (0)