An easy way to get started building JavaScript smart contracts on Zoe. Draft and lightly test your smart contact code here.
The following instructions are written for MacOS. If they don't work for you, or you can contribute instructions for a different platform, please create a new Github issue describing the problem.
- XCode Command Line Tools - you likely will prompted to install this in the terminal as you install the following items.
- Node.js 12.16.2 LTS - this is the JavaScript engine that will run the code
- Homebrew - we will use this in the next step to install
yarn
- Yarn 1 - install using Homebrew in
the terminal by typing
brew install yarn
and hitting Enter.
We recommend using
nvm
to
switch between Node versions as necessary.
We also recommend using Visual Studio Code as your code editor.
In the terminal, navigate to the folder in which you would like to
download Zoe Sketchbook (we recommend a code
directory, created by entering
mkdir code
):
cd code
git clone https://github.com/Agoric/zoe-sketchbook.git
cd zoe-sketchbook
yarn install
Open up Visual Studio Code (VS Code), and open the zoe-sketchbook
folder (you can find it under Users/[your username]/code/
).
You should now see a number of files in the file explorer on the left hand side.
In the
examples/
folder (you can look at this on Github.com, but we recommend viewing
the files locally using VS Code), there are examples of minting fungible tokens
(baytownBucks.js
), and securely trading with another person using
the atomicSwap contract running on Zoe (tradeWithAtomicSwap.js
).
Additionally, all of the contracts written by Agoric for Zoe are
copied into zoe-contracts-copied
for your perusal.
Some of the these examples have tests that you can run and look at to see how they work, and use them as templates to create your own tests. You can find these tests in the test
directory.
To run all of the tests, do: yarn test
from the command
line/terminal.
We use the tape
testing framework. It was installed for you when you
ran yarn install
.
You can add .only
to a test to run only that test:
test.only('timing test', t => {
});
Feel free to make a new file in your local copy (what you just cloned) and write out your own contract. You will probably want to create a test file for your contract as well to make sure it works as intended.
Happy contracting!
- Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
- It may ask you to have a bash profile so that it can add an export for NVM. You can create a profile file by entering:
touch ~/.bash_profile
If you needed to add a bash profile, rerun step 1.
- Close and reopen terminal
- Enter:
nvm install 12.16.2
nvm use 12.16.2
Now you can switch back and forth between installed version of Node by
using the nvm use
command.