Code Monkey home page Code Monkey logo

avalanche-smart-contract-quickstart's Introduction

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.

The Avalanche Network is composed of many blockchains. One of these blockchains is the C-Chain (Contract Chain), which is an Ethereum Virtual Machine instance. The C-Chain's API is almost identical to an Ethereum node's API. Avalanche offers the same interface as Ethereum but with higher speed, higher throughput, lower fees and lower transaction confirmation times. These properties considerably improve the performance of DApps and the user experience of smart contracts.

The goal of this guide is to lay out best practices regarding writing, testing and deployment of smart contracts to Avalanche's C-Chain. We'll be building smart contracts with development environment Hardhat.

Prerequisites

NodeJS and Yarn

First, install the LTS (long-term support) version of nodejs. This is 14.17.0 at the time of writing. NodeJS bundles npm.

Next, install yarn:

npm install -g yarn

AvalancheGo and Avash

AvalancheGo is an Avalanche node implementation written in Go. Avash is a tool to quickly deploy local test networks. Together, you can deploy local test networks and run tests on them.

Solidity and Avalanche

It is also helpful to have a basic understanding of Solidity and Avalanche.

Dependencies

Clone the quickstart repository and install the necessary packages via yarn.

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

Write Contracts

Edit the Coin.sol contract in contracts/. Coin.sol is an Open Zeppelin ERC20 contract. ERC20 is a popular smart contract interface. You can also add your own contracts.

Hardhat Config

Hardhat uses hardhat.config.js as the configuration file. You can define tasks, networks, compilers and more in that file. For more information see here.

In our repository we use a pre-configured file hardhat.config.ts. This file configures necessary network information to provide smooth interaction with Avalanche. There are also some pre-defined private keys for testing on a local test network.

Hardhat Tasks

You can define custom hardhat tasks in hardhat.config.ts.

Documentation

There is a documentation under the Avalanche's official documentation repository: Using Hardhat with the Avalanche C-Chain

avalanche-smart-contract-quickstart's People

Contributors

0fatih avatar ceyonur avatar cgcardona avatar paool avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avalanche-smart-contract-quickstart's Issues

Unknown Chain ID when running yarn fund-cchain-addresses

Upon running yarn fund-cchain-addresses, I receive the following:

yarn run v1.22.10
warning ../../../../../package.json: No license field
$ npx hardhat run scripts/fund-cchain-addresses.js
Exporting 1000 AVAX to each address on the C-Chain...
Error: Error returned: {"jsonrpc":"2.0","error":{"code":-32000,"message":"unknown chain ID","data":null},"id":4}
    at /Users/me/Desktop/Programming/place/otherplace/avalanche-smart-contract-quickstart/node_modules/src/common/jrpcapi.ts:55:19
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at main (/Users/me/Desktop/Programming/place/otherplace/avalanche-smart-contract-quickstart/scripts/fund-cchain-addresses.js:129:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Halp.

docker compose not working due to file structure change in image

$ docker run --rm avaplatform/avalanchego:latest pwd
/avalanchego/build

$ docker run --rm avaplatform/avalanchego:latest ls
avalanchego
plugins

Description of problem
<REPO>/docker-compose/files/start-nodeX.sh runs build/avalanchego in container which does not exist. Latest avalanchego image build has moved PWD from /avalanchego to /avalanchego/build.

Description of problem 2
--db-enabled flag has been deprecated / removed

Transaction underpriced

I have successfully assigned some values for each of accounts but failed to send avax to them or deploy a contract.

Running

yarn balances --network avash

results

0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC has balance 1000000000000000000000
0x9632a79656af553F58738B0FB750320158495942 has balance 1000000000000000000000
0x55ee05dF718f1a5C1441e76190EB1a19eE2C9430 has balance 1000000000000000000000
0x4Cf2eD3665F6bFA95cE6A11CFDb7A2EF5FC1C7E4 has balance 1000000000000000000000
0x0B891dB1901D4875056896f28B6665083935C7A8 has balance 1000000000000000000000
0x01F253bE2EBF0bd64649FA468bF7b95ca933BDe2 has balance 1000000000000000000000
0x78A23300E04FB5d5D2820E23cc679738982e1fd5 has balance 1000000000000000000000
0x3C7daE394BBf8e9EE1359ad14C1C47003bD06293 has balance 1000000000000000000000
0x61e0B3CD93F36847Abbd5d40d6F00a8eC6f3cfFB has balance 1000000000000000000000
0x0Fa8EA536Be85F32724D57A37758761B86416123 has balance 1000000000000000000000

but running

 yarn send-avax --network avash

results

Seeding addresses with AVAX
ProviderError: transaction underpriced

Anyone knows why?

Add environment variables file

Currently when running some scripts, Avash is hard coded as the chain.

It would be good to create an .env file or else a yaml file which then allows users to specify which environment to use.

image

Using `mainnet` hard fork gives `Error: Missing required chain parameter: networkId`

Issue:

Attempting to use mainnet hard fork of hardhat produces the error in title.

Reproduction:

  1. Set hardhat.config.ts FORK_MAINNET to true
  2. Run a script using hardhat run --network hardhat <script>
  3. Call ethers.getSigners()

Error emitting line of script:

const Signer = (await ethers.getSigners())[0];

Hack solution

I was able to get rid of the error by deleting / commenting out:

 //chainId: !forkingData ? 43112 : undefined, //Only specify a chainId if we are not forking

in hardhat.config.ts

Output:

$ npx hardhat run --network hardhat scripts/<script>
Error: Missing required chain parameter: networkId
    at Common.setChain (<base_path>/node_modules/@ethereumjs/common/src/index.ts:318:17)
    at new Common (<base_path>/node_modules/@ethereumjs/common/src/index.ts:286:30)
    at Function.forCustomChain (<base_path>/node_modules/@ethereumjs/common/src/index.ts:237:12)
    at Object.makeForkCommon (<base_path>/node_modules/hardhat/src/internal/hardhat-network/provider/utils/makeForkCommon.ts:6:17)
    at Function.create (<base_path>/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:157:22)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at HardhatNetworkProvider._init (<base_path>/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:232:28)
    at HardhatNetworkProvider._send (<base_path>/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:180:5)
    at HardhatNetworkProvider.request (<base_path>/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:106:18)
    at EthersProviderWrapper.send (<base_path>/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Error: problem parsing address

When trying to run through the tutorial I get this error when trying to run fund-cchain-addresses

Error: problem parsing address 'X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u': expected hrp "custom" but got "local"

Refund script doesn't work properly on local network

I tried to follow your manual https://docs.avax.network/dapps/smart-contracts/using-hardhat-with-the-avalanche-c-chain

this part works fine:

yarn accounts --network local
yarn balances --network local

and got stuck with:

yarn fund-cchain-addresses --network local

Got such errors:

Error - Base58.decode: not a valid base58 string
Exporting 1000 AVAX to each address on the C-Chain...
Error: problem decoding transaction: missing 0x prefix to hex encoding
at AVMAPI. (/Users/apple/dev/smartcontracts/avalanche-smart-contract-quickstart/node_modules/src/common/jrpcapi.ts:68:15)
at Generator.next ()
at fulfilled (/Users/apple/dev/smartcontracts/avalanche-smart-contract-quickstart/node_modules/avalanche/dist/common/jrpcapi.js:9:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Smart Contract Upgradability in Avalanche Protocol

Hello Avalanche Team,

Is it possible to make Solidity smart contracts upgradable on Avalanche protocol. Does it follow the same upgradability architecture and approach as in Ethereum. Request for guidance in this regard.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.