Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

smartcontractkit/dapptools-starter-kit

Repository files navigation

Note: As Dapptools has passed the torch to Foundry we recommend you check out the foundry-starter-kit instead.

DappTools Starter Kit


Chainlink DappTools logo


Open in Gitpod

This is based on dapptools-template

You can view a foundry-starter-kit here.

See the #TODO list at the bottom for a list of things to complete.

Implementation of the following 4 Chainlink features using the DappTools development environment:

Installation

Requirements

And you probably already have make installed... but if not try looking here.

Getting Started

git clone https://github.com/smartcontractkit/dapptools-starter-kit
cd dapptools-starter-kit
make # This installs the project's dependencies.
make test

Testing

make test

or

dapp test

All the commands from dapptools work with this repo, like dapp build, ethsign, and dapp test.

Deploying

To deploy, you first need to setup your ethsign and your .env file.

Setup your Account/ethsign

To get your private keys into dapptools, you can either use a keystore or ethsign. ethsign comes with the install of dapptools. For ethsign, run the following:

ethsign import

And you'll be prompted for your private key, and a password. You can get a private key from a wallet like Metamask. Once successful, add the address of the private key to your .env file under an ETH_FROM variable. See the .env.example file for an example.

See the Makefile for more context on how this works under the hood.

If you're going to deploy to a testnet, make sure you have testnet ETH and LINK in your wallet!

Setup your .env file

You can see in the .env.example an example of what your .env should look like (to deploy to a live network).

  1. ALCHEMY_API_KEY: You can find this from getting an Alchemy account.
  2. ETH_FROM: The address of your wallet you want to send transactions from. You must have the private key of the address you want to use loaded into your ethsign, see above for this.
  3. (Optional)ETHERSCAN_API_KEY: For verifying contracts on etherscan.
  4. (Optional)ETH_RPC_URL: For having a default deployment network when using make deploy. This

Testnet & Mainnet Deployment

Set your ETH_RPC_URL or ALCHEMY_API_KEY in your .env file, then run one of the following:

Counters (Keeper Compatible Contract):

make deploy CONTRACT=KeepersCounter

Price Feed:

make deploy CONTRACT=PriceFeedConsumer

Chainlink VRF Consumer:

make deploy CONTRACT=VRFConsumerV2

Chainlink API contract:

make deploy CONTRACT=APIConsumer

You can change their deployment parameters in their respective deploy file in the scripts folder. All the constructor arguments are created in the ./scripts/helper-config.sh folder. This is where you can assign different constructor arguments across networks.

Local Testnet

# on one terminal
dapp testnet

Change your ETH_RPC_URL to http://127.0.0.1:8545

Then run your deploy script.

Verifying on Etherscan

After deploying your contract you can verify it on Etherscan using:

ETHERSCAN_API_KEY=<api-key> dapp verify-contract <contract_directory>/<contract>:<contract_name> <contract_address>

For example:

ETHERSCAN_API_KEY=123456765 dapp verify-contract ./src/KeepersCounter.sol:KeepersCounter 0x23456534212536435424

Check out the dapp documentation to see how verifying contracts work with DappTools.

Interacting with your contracts

To interact with our contracts, we use the seth command. Let's say we've deployed our PriceFeedConsumer.sol to kovan, and now we want to call the getLatestPrice function. How do we do this?

ETH_RPC_URL=<YOUR_RPC_URL> seth call <YOUR_CONTRACT_ADDRESS> "getLatestPrice()"

For example:

ETH_RPC_URL=https://alchemy.io/adsfasdf seth call 0xd39F749195Ab1B4772fBB496EDAF56729ee36E55 "getLatestPrice()"

This will give us an output like 0x0000000000000000000000000000000000000000000000000000004c17b125c0 which is the hex of 326815000000

This is to call transactions (not spend gas). To change the state of the blockchain (spend gas) we'd use seth send. Let's say we have a VRFConsumer contract deployed, and we want to call getRandomNumber:

First, we'd need to send our contract some LINK on the Kovan Chain:

ETH_RPC_URL=<YOUR_RPC_URL> ETH_FROM=<YOUR_FROM_ADDRESS> seth send <LINK_TOKEN_ADDRESS> "transfer(address,uint256)" <VRF_CONSUMER_ADDRESS> 1000000000000000000

Like:

ETH_RPC_URL=https://alchemy.io/adfasdf ETH_FROM=0x12345 seth send 0xa36085F69e2889c224210F603D836748e7dC0088 "transfer(address,uint256)" 0xa74576956E24a8Fa768723Bd5284BcBE1Ea03adA 100000000000000000

Where 100000000000000000 = 1 LINK

Then, we could call the getRandomNumber function:

ETH_RPC_URL=<YOUR_RPC_URL> ETH_FROM=<YOUR_FROM_ADDRESS> seth send <VRF_CONSUMER_ADDRESS>  "getRandomNumber()"

And after a slight delay, read the result:

ETH_RPC_URL=<YOUR_RPC_URL> seth call <VRF_CONSUMER_ADDRESS> "randomResult()"

As you can see... it would be great to have these scripted in our scripts folder. If you think you want to contribute, please make a PR!

Resources

TODO

[x] Enable network & contract choice from the command line ie: make deploy-rinkeby contract=KeepersCounter

[x] Add mockOracle for any API calls

[ ] Add scripts that interact with deployed contracts

[x] Fix Chainlink VRF deploy script

[x] Add config for parametatizing variables across networks and contracts

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published