Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM Docs: Hardhat and Truffle Configuration #8

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
123 changes: 121 additions & 2 deletions docs/EVM/developer-tooling.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,127 @@ sidebar_position: 3

# Developer Tooling

Deploying and interacting with EVM-based smart contracts on Astar is as easy as any other EVM-compatable network. Usually, getting set up requires two steps:

1. Configuring (and funding) your Ethereum account on the respective network
2. Adding Astar's networks to your Ethereum client

> For Astar and Shiden applications, we *highly* recommend [running your own network node](../nodes/index.md) and not relying on our RPC endpoints. This further decentralizes the network, and puts you in control of your uptime requirements.

## Hardhat

## Remix
### Initialize your project

If you're starting your hardhat project from scratch, we recommend reading the [Hardhat Quick Start](https://hardhat.org/getting-started/#quick-start) page.

### Setting up your account

The quickest way to get Hardhat to deploy contracts to a non-local testnet is to export and use an existing Metamask account.

To get an account's private key from Metamask:

1. Open Metamask
2. Select the account you want to export
3. Click the three dots on the right side
4. Select "Account Details"
5. Select "Export Private Key"
6. Enter your password and select "Confirm"

You should see a 64-character hex string similar to the following:

`60ed0dd24087f00faea4e2b556c74ebfa2f0e705f8169733b01530ce4c619883`

Create a new file in your root folder called `private.json` with your private key in it:

```json
{
"privateKey": "60ed0dd24087f00faea4e2b556c74ebfa2f0e705f8169733b01530ce4c619883"
}
```

Modify your `hardhat.config.js` file to include:

```js
// hardhat.config.js

// ...

const { privateKey } = require('./private.json');

// ...

module.exports = {

// ...

networks: {
// Shibuya faucet: use #shibuya-faucet room in https://discord.gg/astarnetwork
shibuya: {
url: "https://rpc.shibuya.astar.network:8545",
chainId: 81,
accounts: [ privateKey ]
},

// Astar community faucet (please don't abuse): https://as-faucet.xyz/en/astar#
astar: {
url: "https://rpc.astar.network:8545",
chainId: 592,
accounts: [ privateKey ]
},

// Shiden community faucet (please don't abuse): https://as-faucet.xyz/en/shiden#
shiden: {
url: "https://rpc.shiden.astar.network:8545",
chainId: 336,
accounts: [ privateKey ]
}
}
};
```

Once your accounts are funded, you can deploy the sample contract to Shibuya with `npx hardhat run --network shibuya scripts/sample-script.js`.


## Truffle

### Create Ethereum Account

We recommend using the `@truffle/hdwallet-provider` package for key management. Instructions can be found [here](https://github.com/trufflesuite/truffle/blob/develop/packages/hdwallet-provider/README.md).

### Add Networks to `truffle-config.js`

To deploy and interact with Astar, modify `networks` in `truffle-config.js` to include Astar's networks:

```js
// truffle-config.js
module.exports = {

networks: {

// ... any existing networks (development, test, etc.)

// Shibuya faucet: use #shibuya-faucet room in https://discord.gg/astarnetwork
shibuya: {
url: "https://rpc.shibuya.astar.network",
network_id: 81
},

// Astar community faucet (please don't abuse): https://as-faucet.xyz/en/astar#
astar: {
url: "https://rpc.astar.network:8545",
network_id: 592
},

// Shiden community faucet (please don't abuse): https://as-faucet.xyz/en/shiden#
shiden: {
url: "https://rpc.shiden.astar.network:8545",
network_id: 336
}
}

// ...

};
```

## OpenZepplin
Deploy/Migrate by running `truffle migrate --network shibuya`, replacing `shibuya` with your chosen network. If `--network` is not specified, the network values under`development` will be used.