Skip to content

Commit

Permalink
Merge pull request ava-labs#1 from ava-labs/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
Connor Daly authored Jan 26, 2021
2 parents 32e4476 + cd1cf8f commit e13cd9d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
80 changes: 72 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,90 @@
# Writing Smart Contracts on Avalanche
We'll be building smart contracts with Hardhat.

## Introduction

Avalanche is an open-source platform for launching decentralized applications and enterprise blockchain deployments in one interoperable, highly scalable ecosystem. Avalanche gives you complete control on both the network and application layers—helping you build anything you can imagine.

Avalanche can do anything a typical Ethereum client can by using the Ethereum-standard RPC calls. The immediate benefits of using the Avalanche rather than Ethereum are speed, scale and throughput. Avalanche offers thousands of transactions per second with sub-second finality at inexpensive fees. These properties will considerably improve the performance of DApps and the user experience of smart-contracts.

The goal of this guide is to lay out a best-practices regarding writing, testing and deploying smart-contracts to Avalanche. We'll be building smart contracts with [Hardhat](https://hardhat.org) which is an Avalanche development environment for professionals.

## Prerequisites

First install the LTS of [nodejs](https://nodejs.org/en) which is `14.15.4` at the time of writing. NodeJS bundles `npm`. Next install [yarn](https://yarnpkg.com)

```zsh
npm install -g yarn
```

It is also helpful to have a basic understanding of [Solidity](https://docs.soliditylang.org) and [Avalanche](https://docs.avax.network).

## Dependencies
First download the necessary packages.

`yarn`
First clone this repo and download the necessary packages.

```zsh
git clone https://github.com/ava-labs/smart-contract-quickstart.git
cd smart-contract-quickstart
yarn
```

## Write Contracts
Edit the Coin.sol contract in contracts/ or add your own contracts.

Edit the `Coin.sol` contract in `contracts/`. `Coin.sol` is an [Open Zeppelin](https://openzeppelin.com) [ERC20](https://eips.ethereum.org/EIPS/eip-20) contract. ERC20 is a popular smart contract interface for interoperability. You can also add your own contracts.

## Building
Make sure your project compiles with `yarn compile`

In [`package.json`](./package.json) there's a `compile` script.

```json
"compile": "npx hardhat compile",
```

Run `yarn compile` to make sure your project compiles.

## Prepare to Deploy
Edit the deployment script in scripts/deploy.js

Edit the deployment script in `scripts/deploy.js`

## Deploy to the hardhat test network

In [`package.json`](./package.json) there are scripts for deploying to [avash](https://github.com/ava-labs/avash), `fuji` and `mainnet`.

```json
"test-deploy": "npx hardhat run scripts/deploy.js",
"deploy": "npx hardhat run scripts/deploy.js --network mainnet",
"deploy-fuji": "npx hardhat run scripts/deploy.js --network fuji",
```

Deploy your contract to the hardhat network with `yarn test-deploy`.

## Deploy to Fuji or Mainnet
You need to add your private key to the accounts field in `hardhat.config.js`

Then run `yarn deploy` for mainnet or `yarn deploy-fuji` for fuji.
You need to add your private key to the accounts field in [hardhat.config.js](./hardhat.config.js).

Then run `yarn deploy` for mainnet or `yarn deploy-fuji` for fuji.

## Hardhat Tasks

You can define custom hardhat tasks in [hardhat.config.js](./hardhat.config.js). There are two tasks included as examples—`accounts` and `balances` both of which have scripts in [package.json](./package.json).

```json
"accounts": "npx hardhat accounts",
"balances": "npx hardhat balances"
```

`yarn accounts` will print the list of accounts. `yarn balances` prints the list of AVAX account balances.

## Sending AVAX

[package.json](./package.json) has a `send-avax` script which is found in [scripts/sendAvax.js](./scripts/sendAvax.js).

```json
"send-avax": "npx hardhat run scripts/sendAvax.js",
```

Run it with `yarn send-avax`.

## Hardhat Help

You can run `yarn hardhat` to list hardhat version, usage instructions, global options and available tasks.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
"test-deploy": "npx hardhat run scripts/deploy.js",
"deploy": "npx hardhat run scripts/deploy.js --network mainnet",
"deploy-fuji": "npx hardhat run scripts/deploy.js --network fuji",
"send-avax": "npx hardhat run scripts/sendAvax.js",
"lint": "prettier ./test/**/*.ts --check",
"prepublishOnly": "yarn test"
"prepublishOnly": "yarn test",
"hardhat": "npx hardhat",
"accounts": "npx hardhat accounts",
"balances": "npx hardhat balances"
}
}
2 changes: 1 addition & 1 deletion scripts/sendAvax.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const hre = require("hardhat");

const AMOUNT_TO_SEND = '1'
const AMOUNT_TO_SEND = '0.01'

/**
* Sends an amount of AVAX from the first address in the private key pool to the
Expand Down

0 comments on commit e13cd9d

Please sign in to comment.