Setting up a development environment for smart contracts

Some rough notes on using truffle to develop and manually test.

First install truffle and make a new project

npm install -g truffle mkdir foo && cd foo truffle init

Install deps

npm install @openzeppelin/contracts

Edit the contract

Save it and then... * Compile (truffle compile)

Create new script in the migrations folder like migrations/2_foo.js file to select contract

run "truffle develop"

Stash the account list and private keys that show up when you start the console somewhere useful

migrate the contract "migrate"

instantiate

x = await Foo.deployed()

use (hint: use accounts[n] to access account ids.)

metamask:

add new network (RPC url is http://127.0.0.1:9545, chain ID is 1337)

Add some accounts (account 0 is the default admin)

Writing JS:

in truffle developer console, get the address

foo = await Foo.deployed(); foo.address

And get the ABI from the truffle project in build/contracts/*.json HINT: may want to assign names to the return values if many.

Common Errors:

Failed transaction due to "incorrect nonce": Reset your account in metamask.

Returned values aren't valid, did it run Out of Gas?: don't forget to migrate after launching truffle again.

ABI generated by truffle doesn't properly name outputs: if you use outputs by name in web3, be sure to update the abi to name them