Giter Club home page Giter Club logo

klaytn-contracts-old's Introduction

klaytn-contracts

This repository contains contracts that are helpful to building blockchain applications on Klaytn.

Some files were derived from openzeppelin contracts v2.3.0.

Security

WARNING: Please take special care when you use this code in production. We take no responsibility for any security problems you might experience. If you find any security problems in the source code, please report it to [email protected].

Prerequisites

The following packages should be installed before using this source code.

  • git
  • docker
  • Node v10.21.0
  • Truffle v5.1.61
  • ganache-cli v6.12.1
  • jq

Package Installation

Please install node packages first.

$ npm install
$ npm install -g [email protected]
$ npm install -g [email protected]

The package jq is also required. You can install jq by the following command in MacOS:

$ brew install jq

How to run Ganache

Ganache is a local blockchain environment for easy testing. Klaytn is a fork of Ethereum and compatible with Constantinople EVM, so you can use Ganache for testing. To run a Ganache, execute the following command:

$ npm run run:ganache

This ganache network is defined as "development" network in truffle-config.js

How to run a Local Klaytn Network

You can easily deploy a local Klaytn network via the following command:

$ npm run run:klaytn

To see the execution logs, run npm run run:klaytn:log. To stop the network, run npm run run:klaytn:stop. To resume the network, run npm run run:klaytn:resume. To completely terminate the network, run npm run run:klaytn:terminate. To remove log files, run npm run run:klaytn:cleanlog.

How to Test Contracts

Just execute the command as follows:

$ npm run test:ganache

# To run a specific test, execute the below.
$ npm run test:ganache -- ./test/token/KIP7/KIP7.test.js

# To run a test on a local klaytn network, execute the below.
$ npm run test:klaytn
$ npm run test:klaytn -- ./test/token/KIP7/KIP7.test.js

How to Deploy Contracts

Deploying a contract to the local network

  1. To deploy a contract, please modify 2_contract_migration.js. The file deploys a KIP7 contract currently.
  2. Execute the following command to deploy the local network.
$ npm run deploy:klaytn

Deploying a contract to Baobab

Using an EN

Update privateKey and EN URL in baobab of truffle-config.js.

    baobab: {
      provider: () => {
        return new HDWalletProvider(privateKey, "https://your.baobab.en:8651");
      },
      network_id: '1001', //Klaytn baobab testnet's network id
      gas: '8500000',
      gasPrice: null
    },

Using KAS

Also, you can use KAS instead of your own EN. Please refer to kasBaobab as shown below. In this case, you need to update privateKey, accessKeyId, and secretAccessKey.

NOTE: As of Feb 2021, "Using KAS" is not supported yet.

const accessKeyId = "ACCESS_KEY";
const secretAccessKey = "SECRET_KEY";

...

    kasBaobab: {
      provider: () => {
        option.headers['x-chain-id'] = '1001';
        return new HDWalletProvider(privateKey, new Caver.providers.HttpProvider("https://node-api.klaytnapi.com/v1/klaytn", option))
      },
      network_id: '1001', //Klaytn baobab testnet's network id
      gas: '8500000',
      gasPrice:'25000000000'
    },

Deploying a contract to Cypress

Using an EN

Update privateKey and EN URL in baobab of truffle-config.js.

    cypress: {
      provider: () => new HDWalletProvider(privateKey, "https://your.cypress.en:8651"),
      network_id: '8217', //Klaytn mainnet's network id
      gas: '8500000',
      gasPrice: null
    }

Using KAS

Also, you can use KAS instead of your own EN. Please refer to kasBaobab as shown below. In this case, you need to update privateKey, accessKeyId, and secretAccessKey.

NOTE: As of Feb 2021, "Using KAS" is not supported yet.

const accessKeyId = "ACCESS_KEY";
const secretAccessKey = "SECRET_KEY";

...

    kasCypress: {
      provider: () => {
        option.headers['x-chain-id'] = '8217';
        return new HDWalletProvider(privateKey, new Caver.providers.HttpProvider("https://node-api.klaytnapi.com/v1/klaytn", option))
      },
      network_id: '8217', //Klaytn baobab testnet's network id
      gas: '8500000',
      gasPrice:'25000000000'
    },

klaytn-contracts-old's People

Contributors

hackartists avatar iv0rish avatar kjhman21 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

Watchers

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

klaytn-contracts-old's Issues

contract code solidity version 관련 문의

안녕하세요.

혹시 현재 klaytn-contracts 내에 있는 contract code들의 solidity version update 계획이 있으신지 문의드립니다.

https://medium.com/klaytn-kr/klaytn-ide-%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8-9655eb2b6087

상기 링크에서 Klaytn IDE가 solidity 0.8.11까지 지원되도록 업데이트되었다고 나와있는데 Contract Code는 아직 0.5.0 버전으로 작성되어 있는 것 같아서 문의드립니다.

혹시 계획이 없으시다면, 해당 contract code의 compiler 버전을 임의로 올려서 돌리려고 하면 문제가 발생하게 될까요?

감사합니다.

Prerequisites에 추가 부탁드립니다

안녕하세요!
test/init_accounts.shjq가 기본 프로그램이 아니라서, 오류가 계속 발생하고 있었습니다,
번거롭지 않다면 prerequisites에 포함시켜 주시면 좋을거 같습니다 🙏

MACOS사용자라면 아래를 참고 부탁드립니다

brew install jq

test/ 내 코드에 두가지 목적의 소스코드가 혼재되어 있어, 사용성이 떨어졌습니다. *.sh로 이루어진 코드들은 로컬 클레이튼 서버를 띄우기 위해 구성된 소스코드이고, 그외 코드는 테스트 대상 코드라고 비추어져서, 로컬 클레이튼 서버를 띄우기 위한 코드가 분리되는 게 어떨까 합니다.

그래서 로컬 노드를 배포하는 로직을 별도로 나누어, 아래와 같이 리파짓토리로 구성하였습니다.

클레이튼 개발 화이팅입니다!

Solc 0.6.6

Would you mind consider to release a newer npm package for solc >= 0.6.6, Thanks!

Fails to run Local Klaytn Network

When I run following command after pulling master branch, installing required packages, and running ganache without any configuration changes, it prints out an error.

➜  klaytn-contracts git:(master) ✗ npm run run:klaytn            

> [email protected] run:klaytn /Users/kakao/work/klaytn-contracts
> ./test/prepare.sh

~/work/klaytn-contracts/test ~/work/klaytn-contracts
~/work/klaytn-contracts ~/work/klaytn-contracts/test
./init_accounts.sh: line 7: jq: command not found
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to localhost port 8551: Connection refused
FUND_ADDR = 
curl: (7) Failed to connect to localhost port 8551: Connection refused
(node:56739) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
    at /Users/kakao/work/klaytn-contracts/test/init_accounts.js:9:26
    at Object._fireError (/Users/kakao/work/klaytn-contracts/node_modules/caver-js/packages/caver-utils/src/index.js:63:9)
    at /Users/kakao/work/klaytn-contracts/node_modules/caver-js/packages/caver-core-method/src/index.js:255:22
    at /Users/kakao/work/klaytn-contracts/node_modules/caver-js/packages/caver-core-requestmanager/src/index.js:151:28
    at XMLHttpRequest.request.onreadystatechange (/Users/kakao/work/klaytn-contracts/node_modules/caver-js/packages/caver-core-requestmanager/caver-providers-http/src/index.js:122:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/kakao/work/klaytn-contracts/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/Users/kakao/work/klaytn-contracts/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpRequestError (/Users/kakao/work/klaytn-contracts/node_modules/xhr2-cookies/dist/xml-http-request.js:349:14)
    at ClientRequest.<anonymous> (/Users/kakao/work/klaytn-contracts/node_modules/xhr2-cookies/dist/xml-http-request.js:252:61)
    at ClientRequest.emit (events.js:400:28)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:56739) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:56739) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
~/work/klaytn-contracts/test
~/work/klaytn-contracts

But, all tests just work well with $ npm run test:ganache.

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.