diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..8aa924d --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..148d625 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,31 @@ +{ + "env": { + "es6": true, + "node": true + }, + "parserOptions": { + "ecmaVersion": 2017 + }, + "extends": "eslint:recommended", + "rules": { + "indent": [ + "error", + "tab" + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "always" + ] + }, + "plugins": [ + "mocha" + ] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 49445c8..22658e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.idea -node_modules -yarn.lock -build \ No newline at end of file +/.idea +/node_modules +/dist +yarn.lock \ No newline at end of file diff --git a/package.json b/package.json index 6cc0928..0bceb6d 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,24 @@ { "name": "erc20-contract-js", - "version": "1.2.0", + "version": "1.3.0", "description": "Simple JS library used to manipulate with ERC-20 token contracts", "keywords": [ - "ethereum", - "web3", - "javascript", "erc20", + "contract", + "abi", + "javascript", + "web3", + "ethereum", + "eth", + "token", "contract" ], "main": "index.js", + "unpkg": "dist/erc20-contract-js.min.js", + "files": [ + "/src", + "/dist" + ], "repository": "https://github.com/OsoianMarcel/erc20-contract-js.git", "homepage": "https://github.com/OsoianMarcel/erc20-contract-js", "bugs": { @@ -21,12 +30,21 @@ "web3": "^1.0.0-beta.30" }, "devDependencies": { + "@babel/core": "^7.4.3", + "@babel/preset-env": "^7.4.3", + "babel-loader": "^8.0.5", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", + "eslint": "^5.16.0", + "eslint-plugin-mocha": "^5.3.0", "mocha": "^5.0.1", - "web3": "^1.0.0-beta.30" + "web3": "^1.0.0-beta.30", + "webpack": "^4.30.0", + "webpack-cli": "^3.3.0" }, "scripts": { - "test": "mocha" + "test": "mocha", + "build": "webpack", + "lint": "eslint ./src" } } diff --git a/src/ERC20Abi.js b/src/ERC20Abi.js index 8bc9923..d424813 100644 --- a/src/ERC20Abi.js +++ b/src/ERC20Abi.js @@ -1,272 +1,272 @@ module.exports = [ { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ + 'constant': true, + 'inputs': [], + 'name': 'name', + 'outputs': [ { - "name": "", - "type": "string" + 'name': '', + 'type': 'string' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": false, - "inputs": [ + 'constant': false, + 'inputs': [ { - "name": "_spender", - "type": "address" + 'name': '_spender', + 'type': 'address' }, { - "name": "_value", - "type": "uint256" + 'name': '_value', + 'type': 'uint256' } ], - "name": "approve", - "outputs": [ + 'name': 'approve', + 'outputs': [ { - "name": "success", - "type": "bool" + 'name': 'success', + 'type': 'bool' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": true, - "inputs": [], - "name": "totalSupply", - "outputs": [ + 'constant': true, + 'inputs': [], + 'name': 'totalSupply', + 'outputs': [ { - "name": "", - "type": "uint256" + 'name': '', + 'type': 'uint256' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": false, - "inputs": [ + 'constant': false, + 'inputs': [ { - "name": "_from", - "type": "address" + 'name': '_from', + 'type': 'address' }, { - "name": "_to", - "type": "address" + 'name': '_to', + 'type': 'address' }, { - "name": "_value", - "type": "uint256" + 'name': '_value', + 'type': 'uint256' } ], - "name": "transferFrom", - "outputs": [ + 'name': 'transferFrom', + 'outputs': [ { - "name": "success", - "type": "bool" + 'name': 'success', + 'type': 'bool' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": true, - "inputs": [], - "name": "decimals", - "outputs": [ + 'constant': true, + 'inputs': [], + 'name': 'decimals', + 'outputs': [ { - "name": "", - "type": "uint8" + 'name': '', + 'type': 'uint8' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": true, - "inputs": [], - "name": "version", - "outputs": [ + 'constant': true, + 'inputs': [], + 'name': 'version', + 'outputs': [ { - "name": "", - "type": "string" + 'name': '', + 'type': 'string' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": true, - "inputs": [ + 'constant': true, + 'inputs': [ { - "name": "_owner", - "type": "address" + 'name': '_owner', + 'type': 'address' } ], - "name": "balanceOf", - "outputs": [ + 'name': 'balanceOf', + 'outputs': [ { - "name": "balance", - "type": "uint256" + 'name': 'balance', + 'type': 'uint256' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ + 'constant': true, + 'inputs': [], + 'name': 'symbol', + 'outputs': [ { - "name": "", - "type": "string" + 'name': '', + 'type': 'string' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": false, - "inputs": [ + 'constant': false, + 'inputs': [ { - "name": "_to", - "type": "address" + 'name': '_to', + 'type': 'address' }, { - "name": "_value", - "type": "uint256" + 'name': '_value', + 'type': 'uint256' } ], - "name": "transfer", - "outputs": [ + 'name': 'transfer', + 'outputs': [ { - "name": "success", - "type": "bool" + 'name': 'success', + 'type': 'bool' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": false, - "inputs": [ + 'constant': false, + 'inputs': [ { - "name": "_spender", - "type": "address" + 'name': '_spender', + 'type': 'address' }, { - "name": "_value", - "type": "uint256" + 'name': '_value', + 'type': 'uint256' }, { - "name": "_extraData", - "type": "bytes" + 'name': '_extraData', + 'type': 'bytes' } ], - "name": "approveAndCall", - "outputs": [ + 'name': 'approveAndCall', + 'outputs': [ { - "name": "success", - "type": "bool" + 'name': 'success', + 'type': 'bool' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "constant": true, - "inputs": [ + 'constant': true, + 'inputs': [ { - "name": "_owner", - "type": "address" + 'name': '_owner', + 'type': 'address' }, { - "name": "_spender", - "type": "address" + 'name': '_spender', + 'type': 'address' } ], - "name": "allowance", - "outputs": [ + 'name': 'allowance', + 'outputs': [ { - "name": "remaining", - "type": "uint256" + 'name': 'remaining', + 'type': 'uint256' } ], - "payable": false, - "type": "function" + 'payable': false, + 'type': 'function' }, { - "inputs": [ + 'inputs': [ { - "name": "_initialAmount", - "type": "uint256" + 'name': '_initialAmount', + 'type': 'uint256' }, { - "name": "_tokenName", - "type": "string" + 'name': '_tokenName', + 'type': 'string' }, { - "name": "_decimalUnits", - "type": "uint8" + 'name': '_decimalUnits', + 'type': 'uint8' }, { - "name": "_tokenSymbol", - "type": "string" + 'name': '_tokenSymbol', + 'type': 'string' } ], - "type": "constructor" + 'type': 'constructor' }, { - "payable": false, - "type": "fallback" + 'payable': false, + 'type': 'fallback' }, { - "anonymous": false, - "inputs": [ + 'anonymous': false, + 'inputs': [ { - "indexed": true, - "name": "_from", - "type": "address" + 'indexed': true, + 'name': '_from', + 'type': 'address' }, { - "indexed": true, - "name": "_to", - "type": "address" + 'indexed': true, + 'name': '_to', + 'type': 'address' }, { - "indexed": false, - "name": "_value", - "type": "uint256" + 'indexed': false, + 'name': '_value', + 'type': 'uint256' } ], - "name": "Transfer", - "type": "event" + 'name': 'Transfer', + 'type': 'event' }, { - "anonymous": false, - "inputs": [ + 'anonymous': false, + 'inputs': [ { - "indexed": true, - "name": "_owner", - "type": "address" + 'indexed': true, + 'name': '_owner', + 'type': 'address' }, { - "indexed": true, - "name": "_spender", - "type": "address" + 'indexed': true, + 'name': '_spender', + 'type': 'address' }, { - "indexed": false, - "name": "_value", - "type": "uint256" + 'indexed': false, + 'name': '_value', + 'type': 'uint256' } ], - "name": "Approval", - "type": "event" + 'name': 'Approval', + 'type': 'event' }, ]; \ No newline at end of file diff --git a/src/examples/basic.js b/src/examples/basic.js deleted file mode 100644 index 43ef076..0000000 --- a/src/examples/basic.js +++ /dev/null @@ -1,25 +0,0 @@ -const Web3 = require('web3'); -const ERC20Contract = require('../ERC20Contract'); - -// Web3 instance -const web3 = new Web3( - new Web3.providers.HttpProvider('https://mainnet.infura.io') -); - -const walletAddr = '0x8d12a197cb00d4747a1fe03395095ce2a5cc6819', // EtherDelta contract address - contractAddr = '0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0'; // EOS contract address - -// Create new instance of ERC20Contract -const erc20Contract = new ERC20Contract(web3, contractAddr); - -// Get balance of -erc20Contract.balanceOf(walletAddr).call() - .then(balance => console.log(`Balance: ${balance}`)); - -// Get total supply -erc20Contract.totalSupply().call() - .then(totalBalance => console.log(`Total supply: ${totalBalance}`)); - -// Get allowance -erc20Contract.allowance(walletAddr, walletAddr).call() - .then(allowance => console.log(`Allowance: ${allowance}`)); \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..a05cfbb --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,18 @@ +const path = require('path'); + +module.exports = { + mode: 'production', + entry: './src/ERC20Contract', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'erc20-contract-js.min.js', + libraryTarget: 'umd', + globalObject: 'this', + library: 'ERC20ContractJs' + }, + module: { + rules: [ + {test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'} + ] + } +}; \ No newline at end of file