├── .gitignore
├── .vscode
└── settings.json
├── .gitattributes
├── frontend
├── public
│ ├── robots.txt
│ ├── favicon.ico
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── index.html
├── src
│ ├── setupTests.js
│ ├── App.test.js
│ ├── reportWebVitals.js
│ ├── index.js
│ ├── App.css
│ ├── index.css
│ ├── pages
│ │ ├── CreateWallet.js
│ │ ├── BnbBalance.js
│ │ ├── TokenBalance.js
│ │ ├── ImportWallet.js
│ │ ├── SendBnb.js
│ │ └── SendToken.js
│ ├── App.js
│ └── logo.svg
├── .gitignore
├── package.json
├── README.md
└── .eslintcache
├── demo
└── example.js
├── package.json
├── server.js
├── README.md
├── src
├── bep20ABI.json
└── centerpirme.js
└── contract
└── bep20-token.sol
/.gitignore:
--------------------------------------------------------------------------------
1 | # node_modules
2 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "git.ignoreLimitWarning": true
3 | }
4 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/frontend/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/frontend/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/centerprime/BinanceSmartChain-NodeJS-SDK/HEAD/frontend/public/favicon.ico
--------------------------------------------------------------------------------
/frontend/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/centerprime/BinanceSmartChain-NodeJS-SDK/HEAD/frontend/public/logo192.png
--------------------------------------------------------------------------------
/frontend/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/centerprime/BinanceSmartChain-NodeJS-SDK/HEAD/frontend/public/logo512.png
--------------------------------------------------------------------------------
/frontend/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------
/frontend/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from '@testing-library/react';
2 | import App from './App';
3 |
4 | test('renders learn react link', () => {
5 | render();
6 | const linkElement = screen.getByText(/learn react/i);
7 | expect(linkElement).toBeInTheDocument();
8 | });
9 |
--------------------------------------------------------------------------------
/frontend/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/frontend/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 |
7 | ReactDOM.render(, document.getElementById('root'));
8 |
9 | // If you want to start measuring performance in your app, pass a function
10 | // to log results (for example: reportWebVitals(console.log))
11 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
12 | reportWebVitals();
13 |
--------------------------------------------------------------------------------
/frontend/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/frontend/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | height: 40vmin;
7 | pointer-events: none;
8 | }
9 |
10 | @media (prefers-reduced-motion: no-preference) {
11 | .App-logo {
12 | animation: App-logo-spin infinite 20s linear;
13 | }
14 | }
15 |
16 | .App-header {
17 | background-color: #282c34;
18 | min-height: 100vh;
19 | display: flex;
20 | flex-direction: column;
21 | align-items: center;
22 | justify-content: center;
23 | font-size: calc(10px + 2vmin);
24 | color: white;
25 | }
26 |
27 | .App-link {
28 | color: #61dafb;
29 | }
30 |
31 | @keyframes App-logo-spin {
32 | from {
33 | transform: rotate(0deg);
34 | }
35 | to {
36 | transform: rotate(360deg);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/demo/example.js:
--------------------------------------------------------------------------------
1 | import BnbManager from "../src/centerpirme.js";
2 |
3 | var bnbManager = new BnbManager("https://data-seed-prebsc-1-s1.binance.org:8545");
4 | bnbManager.getBEPTokenBalance("0x6ce8da28e2f864420840cf74474eff5fd80e65b8","0x082a2027dc16f42d6e69be8fa13c94c17c910ebe").then(
5 | res=>{
6 | console.log(res);
7 | }, error=>{
8 | console.log(error);
9 | }
10 | );
11 |
12 |
13 | let keystore = {};
14 | let password = "";
15 | let amount = 12
16 | let toAddress = '0x38C1E1204C10C8be90ecA671Da8Ea8a9AEb16031'
17 |
18 |
19 | let tokenContractAddress = '0xa1825717848bdeb9b1b2389471fe0d98c0af71a5';
20 |
21 | bnbManager.sendToken(keystore,password,tokenContractAddress, toAddress,amount,3).then(res=>{
22 | console.log(res);
23 | })
--------------------------------------------------------------------------------
/frontend/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
12 | monospace;
13 | }
14 |
15 | .content {
16 | padding: 20px;
17 | }
18 |
19 | .header {
20 | padding: 10px;
21 | background: #edf2f4;
22 | border-bottom: 1px solid #999;
23 | }
24 | .header a {
25 | color: #0072ff;
26 | text-decoration: none;
27 | margin-left: 20px;
28 | margin-right: 5px;
29 | }
30 | .header a:hover {
31 | color: #8a0f53;
32 | }
33 | .header small {
34 | color: #666;
35 | }
36 | .header .active {
37 | color: #2c7613;
38 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "node-binance-sdk",
3 | "version": "1.0.5",
4 | "description": "Centerprime Node Binance Smart Chain SDK",
5 | "type": "module",
6 | "main": "src/centerprime.js",
7 | "keywords": [
8 | "ethereum",
9 | "blockchain",
10 | "sdk",
11 | "web3",
12 | "binance"
13 | ],
14 | "author": "Centerprime",
15 | "license": "UNLICENSED",
16 | "spm": {
17 | "main": "src/centerprime.js"
18 | },
19 | "devDependencies": {},
20 | "dependencies": {
21 | "axios": "^0.21.1",
22 | "express": "^4.17.1",
23 | "web3": "^1.3.1"
24 | },
25 | "repository": {
26 | "type": "git",
27 | "url": "git+https://github.com/centerprime/Node-Binance-SDK.git"
28 | },
29 | "bugs": {
30 | "url": "https://github.com/centerprime/Node-Binance-SDK/issues"
31 | },
32 | "homepage": "https://github.com/centerprime/Node-Binance-SDK#readme"
33 | }
34 |
--------------------------------------------------------------------------------
/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "frontend",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.11.8",
7 | "@testing-library/react": "^11.2.2",
8 | "@testing-library/user-event": "^12.6.0",
9 | "react": "^17.0.1",
10 | "react-dom": "^17.0.1",
11 | "react-router-dom": "^5.2.0",
12 | "react-scripts": "4.0.1",
13 | "web-vitals": "^0.2.4"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test",
19 | "eject": "react-scripts eject"
20 | },
21 | "eslintConfig": {
22 | "extends": [
23 | "react-app",
24 | "react-app/jest"
25 | ]
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/frontend/src/pages/CreateWallet.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react';
2 | import axios from 'axios';
3 |
4 |
5 | function Home() {
6 |
7 |
8 | const [loading, setLoading] = useState(false);
9 | const password = useFormInput('');
10 | const [error, setError] = useState(null);
11 | const [keystore, setKeystore] = useState(null);
12 |
13 | // handle button click of login form
14 | const handleLogin = () => {
15 | setError(null);
16 | setLoading(true);
17 | axios.post('http://localhost:3080/api/createWallet', { password: password.value }).then(response => {
18 | console.log(JSON.stringify(response.data));
19 | setKeystore(JSON.stringify(response.data.keystore));
20 | setLoading(false);
21 | }).catch(error => {
22 | setLoading(false);
23 | if (error.response.status === 401) setError(error.response.data.message);
24 | else setError("Something went wrong. Please try again later.");
25 | });
26 | }
27 |
28 |
29 | return (
30 |
31 | Create Wallet
32 |
33 | Password
34 |
35 |
36 |
37 |
38 | Keystore
39 |
41 | );
42 | }
43 |
44 | const useFormInput = initialValue => {
45 | const [value, setValue] = useState(initialValue);
46 |
47 | const handleChange = e => {
48 | setValue(e.target.value);
49 | }
50 | return {
51 | value,
52 | onChange: handleChange
53 | }
54 | }
55 |
56 | export default Home;
--------------------------------------------------------------------------------
/frontend/src/pages/BnbBalance.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react';
2 | import axios from 'axios';
3 |
4 |
5 | function BnbBalance() {
6 |
7 |
8 | const [loading, setLoading] = useState(false);
9 | const address = useFormInput('');
10 | const [error, setError] = useState(null);
11 |
12 | // handle button click of login form
13 | const handleLogin = () => {
14 | setError(null);
15 | setLoading(true);
16 | let addressTxt = address.value;
17 | if(addressTxt === ''){
18 | setLoading(false);
19 | setError("Please fill the fileds");
20 | } else {
21 | axios.post('http://localhost:3080/api/bnbBalance', { address: address.value }).then(response => {
22 | console.log(JSON.stringify(response.data));
23 | setLoading(false);
24 | setError(response.data)
25 | }).catch(error => {
26 | setLoading(false);
27 | if (error.response.status === 401) setError(error.response.data.message);
28 | else setError("Something went wrong. Please try again later.");
29 | });
30 | }
31 |
32 | }
33 |
34 |
35 | return (
36 |
37 |
38 | Address
39 |
40 |
41 |
42 |
43 |
44 |
{error}
45 |
46 | );
47 | }
48 |
49 | const useFormInput = initialValue => {
50 | const [value, setValue] = useState(initialValue);
51 |
52 | const handleChange = e => {
53 | setValue(e.target.value);
54 | }
55 | return {
56 | value,
57 | onChange: handleChange
58 | }
59 | }
60 |
61 | export default BnbBalance;
--------------------------------------------------------------------------------
/frontend/src/App.js:
--------------------------------------------------------------------------------
1 | import logo from './logo.svg';
2 | import './App.css';
3 | import { BrowserRouter, Switch, Route, NavLink } from 'react-router-dom';
4 | import CreateWallet from './pages/CreateWallet';
5 | import ImportWallet from './pages/ImportWallet';
6 | import BnbBalance from './pages/BnbBalance';
7 | import TokenBalance from './pages/TokenBalance';
8 | import SendBnb from './pages/SendBnb';
9 | import SendToken from './pages/SendToken';
10 |
11 | function App() {
12 | return (
13 |
14 |
15 |
16 |
17 | Create Wallet
18 | Import Wallet
19 | Bnb Balance
20 | Token Balance
21 | Send Bnb
22 | Send Token
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | );
38 | }
39 |
40 | export default App;
41 |
--------------------------------------------------------------------------------
/frontend/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/frontend/src/pages/TokenBalance.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react';
2 | import axios from 'axios';
3 |
4 |
5 | function TokenBalance() {
6 |
7 |
8 | const [loading, setLoading] = useState(false);
9 | const address = useFormInput('');
10 | const tokenAddress = useFormInput('');
11 | const [error, setError] = useState(null);
12 |
13 | // handle button click of login form
14 | const handleLogin = () => {
15 | setError(null);
16 | setLoading(true);
17 | let addressTxt = address.value;
18 | let tokenAddressTxt = tokenAddress.value;
19 | if(addressTxt === '' || tokenAddressTxt === ''){
20 | setLoading(false);
21 | setError("Please fill the fileds");
22 | } else {
23 | axios.post('http://localhost:3080/api/tokenBalance', { address: address.value , tokenAddress : tokenAddressTxt }).then(response => {
24 | console.log(JSON.stringify(response));
25 | setLoading(false);
26 | setError(response.data)
27 | }).catch(error => {
28 | setLoading(false);
29 | if (error.response.status === 401) setError(error.response.data.message);
30 | else setError("Something went wrong. Please try again later.");
31 | });
32 | }
33 |
34 | }
35 |
36 | return (
37 |
38 |
39 | Address
40 |
41 |
42 |
43 |
44 | Token Address
45 |
46 |
47 |
48 |
49 |
50 |
{error}
51 |
52 | );
53 |
54 | }
55 |
56 | const useFormInput = initialValue => {
57 | const [value, setValue] = useState(initialValue);
58 |
59 | const handleChange = e => {
60 | setValue(e.target.value);
61 | }
62 | return {
63 | value,
64 | onChange: handleChange
65 | }
66 | }
67 |
68 | export default TokenBalance;
--------------------------------------------------------------------------------
/frontend/src/pages/ImportWallet.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react';
2 | import axios from 'axios';
3 |
4 |
5 | function ImportWallet() {
6 |
7 |
8 | const [loading, setLoading] = useState(false);
9 | const password = useFormInput('');
10 | const [error, setError] = useState(null);
11 | const keystore = useFormInput('');
12 | const [result, setResult] = useState(null);
13 |
14 | // handle button click of login form
15 | const handleLogin = () => {
16 | setError(null);
17 | setLoading(true);
18 | let passwordTxt = password.value;
19 | let keystoreTxt = keystore.value;
20 | if(passwordTxt === '' || keystoreTxt === ''){
21 | setLoading(false);
22 | setError("Please fill the fileds");
23 | } else {
24 | axios.post('http://localhost:3080/api/importWallet', { password: password.value, keystore : keystore.value }).then(response => {
25 | console.log(JSON.stringify(response.data));
26 | setLoading(false);
27 | setError("SUCCESS")
28 | }).catch(error => {
29 | setLoading(false);
30 | if (error.response.status === 401) setError(error.response.data.message);
31 | else setError("Something went wrong. Please try again later.");
32 | });
33 | }
34 |
35 | }
36 |
37 |
38 | return (
39 |
52 | );
53 | }
54 |
55 | const useFormInput = initialValue => {
56 | const [value, setValue] = useState(initialValue);
57 |
58 | const handleChange = e => {
59 | setValue(e.target.value);
60 | }
61 | return {
62 | value,
63 | onChange: handleChange
64 | }
65 | }
66 |
67 | export default ImportWallet;
--------------------------------------------------------------------------------
/frontend/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/frontend/src/pages/SendBnb.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react';
2 | import axios from 'axios';
3 |
4 |
5 | function SendEther() {
6 | const password = useFormInput('');
7 | const keystore = useFormInput('');
8 | const toAddress = useFormInput('');
9 | const amount = useFormInput('');
10 |
11 | const [loading, setLoading] = useState(false);
12 | const [error, setError] = useState(null);
13 |
14 | // handle button click of login form
15 | const handleLogin = () => {
16 | setError(null);
17 | setLoading(true);
18 | let passwordT = password.value;
19 | let keystoreT = keystore.value;
20 | let toAddressT = toAddress.value;
21 | let amountT = amount.value;
22 | if(passwordT === '' || keystoreT === '' || toAddressT === '' || amountT === ''){
23 | setLoading(false);
24 | setError("Please fill the fileds");
25 | } else {
26 | axios.post('http://localhost:3080/api/sendBnb', {
27 | keystore: keystoreT,
28 | password: passwordT,
29 | toAddress : toAddressT,
30 | amount : amountT
31 | }).then(response => {
32 | console.log(JSON.stringify(response.data));
33 | setLoading(false);
34 | setError(response.data)
35 | }).catch(error => {
36 | setLoading(false);
37 | if (error.response.status === 401) setError(error.response.data.message);
38 | else setError("Something went wrong. Please try again later.");
39 | });
40 | }
41 |
42 | }
43 |
44 |
45 | return (
46 |
68 | );
69 | }
70 |
71 | const useFormInput = initialValue => {
72 | const [value, setValue] = useState(initialValue);
73 |
74 | const handleChange = e => {
75 | setValue(e.target.value);
76 | }
77 | return {
78 | value,
79 | onChange: handleChange
80 | }
81 | }
82 |
83 | export default SendEther;
--------------------------------------------------------------------------------
/frontend/src/pages/SendToken.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react';
2 | import axios from 'axios';
3 |
4 |
5 | function SendToken() {
6 | const password = useFormInput('');
7 | const keystore = useFormInput('');
8 | const tokenContractAddress = useFormInput('');
9 | const toAddress = useFormInput('');
10 | const amount = useFormInput('');
11 |
12 | const [loading, setLoading] = useState(false);
13 | const [error, setError] = useState(null);
14 |
15 | // handle button click of login form
16 | const handleLogin = () => {
17 | setError(null);
18 | setLoading(true);
19 | let passwordT = password.value;
20 | let keystoreT = keystore.value;
21 | let toAddressT = toAddress.value;
22 | let amountT = amount.value;
23 | let tokenContractAddressT = tokenContractAddress.value
24 | if(passwordT === '' || keystoreT === '' || toAddressT === '' || amountT === '' || tokenContractAddressT === ''){
25 | setLoading(false);
26 | setError("Please fill the fileds");
27 | } else {
28 | axios.post('http://localhost:3080/api/sendToken', {
29 | keystore: keystoreT,
30 | password: passwordT,
31 | tokenContractAddress : tokenContractAddressT,
32 | toAddress : toAddressT,
33 | amount : amountT
34 | }).then(response => {
35 | console.log(JSON.stringify(response.data));
36 | setLoading(false);
37 | setError(response.data.transactionHash)
38 | }).catch(error => {
39 | setLoading(false);
40 | if (error.response.status === 401) setError(error.response.data.message);
41 | else setError("Something went wrong. Please try again later.");
42 | });
43 | }
44 |
45 | }
46 |
47 |
48 | return (
49 |
76 | );
77 | }
78 |
79 | const useFormInput = initialValue => {
80 | const [value, setValue] = useState(initialValue);
81 |
82 | const handleChange = e => {
83 | setValue(e.target.value);
84 | }
85 | return {
86 | value,
87 | onChange: handleChange
88 | }
89 | }
90 |
91 | export default SendToken;
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | import express from 'express';
2 | import bodyParser from 'body-parser'
3 | import BnbManager from "./src/centerpirme.js";
4 | import cors from 'cors';
5 |
6 |
7 | var bnbManager = new BnbManager("https://data-seed-prebsc-1-s1.binance.org:8545");
8 | const app = express(),
9 | port = 3080;
10 |
11 | // place holder for the data
12 | const users = [];
13 | app.use(cors())
14 | app.use(bodyParser.json());
15 |
16 | app.post('/api/createWallet', (req, res) => {
17 | const password = req.body.password;
18 | let wallet = bnbManager.createAccount(password)
19 | console.log(wallet);
20 | res.json(wallet);
21 | });
22 |
23 |
24 | app.post('/api/importWallet', (req, res) => {
25 | try {
26 | const password = req.body.password;
27 | const keystore = req.body.keystore;
28 | let wallet = bnbManager.importWalletByKeystore(keystore,password)
29 | console.log(wallet);
30 | res.json(wallet);
31 | } catch(e) {
32 | return res.status(401).send({
33 | message : e.message
34 | });
35 | }
36 | });
37 |
38 | app.post('/api/bnbBalance', async function(req,res) {
39 | try {
40 | const address = req.body.address;
41 | let balance = await bnbManager.getBnbBalance(address)
42 | console.log(balance);
43 | res.json(balance);
44 | } catch(e) {
45 | return res.status(401).send({
46 | message : e.message
47 | });
48 | }
49 | });
50 |
51 | app.post('/api/tokenBalance', async function(req,res) {
52 | try {
53 | const address = req.body.address;
54 | const tokenContractAddress = req.body.tokenAddress;
55 | let balance = await bnbManager.getBEPTokenBalance(tokenContractAddress,address)
56 | console.log(balance);
57 | res.json(balance);
58 | } catch(e) {
59 | return res.status(401).send({
60 | message : e.message
61 | });
62 | }
63 | });
64 |
65 |
66 | app.post('/api/sendBnb', async function(req,res) {
67 | try {
68 | const keystore = req.body.keystore;
69 | const password = req.body.password;
70 | const toAddress = req.body.toAddress;
71 | const amount = req.body.amount;
72 | let balance = await bnbManager.sendBNB(keystore,password,toAddress,amount,3)
73 | console.log(balance);
74 | res.json(balance);
75 | } catch(e) {
76 | return res.status(401).send({
77 | message : e.message
78 | });
79 | }
80 | });
81 |
82 | app.post('/api/sendToken', async function(req,res) {
83 | try {
84 | const keystore = req.body.keystore;
85 | const password = req.body.password;
86 | const tokenContractAddress = req.body.tokenContractAddress;
87 | const toAddress = req.body.toAddress;
88 | const amount = req.body.amount;
89 | let balance = await bnbManager.sendToken(keystore,password,tokenContractAddress,toAddress,parseFloat(amount),3)
90 | console.log(balance);
91 | res.json(balance);
92 | } catch(e) {
93 | return res.status(401).send({
94 | message : e.message
95 | });
96 | }
97 | });
98 |
99 | app.listen(port, () => {
100 | console.log(`Server listening on the port::${port}`);
101 | });
--------------------------------------------------------------------------------
/frontend/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13 |
14 | The page will reload if you make edits.\
15 | You will also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35 |
36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39 |
40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/frontend/.eslintcache:
--------------------------------------------------------------------------------
1 | [{"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/index.js":"1","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/reportWebVitals.js":"2","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/App.js":"3","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/CreateWallet.js":"4","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/BnbBalance.js":"5","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/SendToken.js":"6","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/ImportWallet.js":"7","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/SendBnb.js":"8","/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/TokenBalance.js":"9"},{"size":449,"mtime":1610073016409,"results":"10","hashOfConfig":"11"},{"size":362,"mtime":1610073016410,"results":"12","hashOfConfig":"11"},{"size":1641,"mtime":1610073016408,"results":"13","hashOfConfig":"11"},{"size":1536,"mtime":1610073016409,"results":"14","hashOfConfig":"11"},{"size":1520,"mtime":1610073016409,"results":"15","hashOfConfig":"11"},{"size":2610,"mtime":1610073016410,"results":"16","hashOfConfig":"11"},{"size":1808,"mtime":1610073016409,"results":"17","hashOfConfig":"11"},{"size":2238,"mtime":1610073016409,"results":"18","hashOfConfig":"11"},{"size":1798,"mtime":1610089350806,"results":"19","hashOfConfig":"11"},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1s6tb0n",{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"26","messages":"27","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"28","messages":"29","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"30","messages":"31","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"32","messages":"33","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"34","messages":"35","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/index.js",[],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/reportWebVitals.js",[],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/App.js",["38"],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/CreateWallet.js",["39"],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/BnbBalance.js",[],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/SendToken.js",[],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/ImportWallet.js",["40","41"],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/SendBnb.js",[],"/Users/htnteam/IdeaProjects/NodeProjects/bnb/BinanceSmartChain-NodeJS-SDK/frontend/src/pages/TokenBalance.js",[],{"ruleId":"42","severity":1,"message":"43","line":1,"column":8,"nodeType":"44","messageId":"45","endLine":1,"endColumn":12},{"ruleId":"42","severity":1,"message":"46","line":10,"column":12,"nodeType":"44","messageId":"45","endLine":10,"endColumn":17},{"ruleId":"42","severity":1,"message":"47","line":12,"column":12,"nodeType":"44","messageId":"45","endLine":12,"endColumn":18},{"ruleId":"42","severity":1,"message":"48","line":12,"column":20,"nodeType":"44","messageId":"45","endLine":12,"endColumn":29},"no-unused-vars","'logo' is defined but never used.","Identifier","unusedVar","'error' is assigned a value but never used.","'result' is assigned a value but never used.","'setResult' is assigned a value but never used."]
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Binance SmartChain NodeJS SDK
2 |
3 | ## Prerequisites
4 |
5 | This project requires NodeJS (version 8 or later) and NPM.
6 | [Node](http://nodejs.org/) and [NPM](https://npmjs.org/) are really easy to install.
7 | To make sure you have them available on your machine,
8 | try running the following command.
9 |
10 | ```sh
11 | $ npm -v && node -v
12 | 6.4.1
13 | v8.16.0
14 | ```
15 |
16 | ## Table of contents
17 |
18 | - [Project Name](#project-name)
19 | - [Prerequisites](#prerequisites)
20 | - [Table of contents](#table-of-contents)
21 | - [Getting Started](#getting-started)
22 | - [Installation](#installation)
23 | - [API](#api)
24 | - [Create Wallet](#createwallet)
25 | - [Import Wallet](#importwallet)
26 | - [Keystore](#keystore)
27 | - [Private Key](#keystore)
28 | - [Balance](#balance)
29 | - [BNB Balance](#etherbalance)
30 | - [BEP20 Token Balance](#erc20tokenbalance)
31 | - [Send](#send)
32 | - [Send BNB](#sendether)
33 | - [Send BEP20 Token](#senderc20token)
34 | - [Demo](#demo)
35 |
36 | ## Getting Started
37 |
38 | These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
39 |
40 | ## Installation
41 |
42 | **BEFORE YOU INSTALL:** please read the [prerequisites](#prerequisites)
43 |
44 | Start with cloning this repo on your local machine:
45 |
46 | ```sh
47 | $ git clone https://github.com/centerprime/Node-Binance-SDK.git
48 | ```
49 |
50 | To install and set up the library, run:
51 |
52 | ```sh
53 | $ npm install node-binance-sdk
54 | ```
55 |
56 | ## API
57 |
58 | ### Create Wallet
59 |
60 | ```js
61 | import BnbManager from "../src/centerprime.js";
62 |
63 | var bnbManager = new BnbManager("Infura Url");
64 | bnbManager.createAccount("12345")
65 | .then(res => {
66 | console.log(res);
67 | });
68 | ```
69 |
70 |
71 | ### Import Wallet by Keystore
72 |
73 | ```js
74 | import BnbManager from "../src/centerprime.js";
75 |
76 | var bnbManager = new BnbManager("Infura Url");
77 | let keystore = {};
78 | let password = '';
79 | bnbManager.importWalletByKeystore(keystore,password)
80 | .then(res => {
81 | console.log(res);
82 | });
83 | ```
84 |
85 | ### Import Wallet by Private key
86 |
87 | ```js
88 | import BnbManager from "../src/centerprimeSDK.js";
89 |
90 | var bnbManager = new BnbManager("Infura Url");
91 | let privateKey = '';
92 | bnbManager.importWalletByPrivateKey(privateKey)
93 | .then(res => {
94 | console.log(res);
95 | });
96 | ```
97 |
98 | ### Get BNB balance
99 |
100 | ```js
101 | import BnbManager from "../src/centerprimeSDK.js";
102 |
103 | var bnbManager = new BnbManager("Infura Url");
104 | let address = '';
105 | bnbManager.getBnbBalance(address)
106 | .then(res => {
107 | console.log(res);
108 | });
109 | ```
110 |
111 |
112 | ### Get BEP20 token balance
113 |
114 | ```js
115 | import BnbManager from "../src/centerprimeSDK.js";
116 |
117 | var bnbManager = new BnbManager("Infura Url");
118 | let tokenContractAddress = '';
119 | let address = '';
120 | bnbManager.getBEPTokenBalance(tokenContractAddress, address)
121 | .then(res => {
122 | console.log(res);
123 | });
124 | ```
125 |
126 | ### Send BEP20 token
127 |
128 | ```js
129 | import BnbManager from "../src/centerprimeSDK.js";
130 |
131 | var bnbManager = new BnbManager("Infura Url");
132 | let keystore = {};
133 | let password = '';
134 | let tokenContractAddress = '';
135 | let toAddress = '';
136 | let amount = '';
137 | let chainId = ''; // 1 : Mainnet 3 : Ropsten
138 | bnbManager.sendToken(keystore, password, tokenContractAddress , toAddress , amount , chainId)
139 | .then(res => {
140 | console.log(res);
141 | });
142 | ```
143 |
144 |
145 | ### Send BNB
146 |
147 | ```js
148 | import BnbManager from "../src/centerprimeSDK.js";
149 |
150 | var bnbManager = new BnbManager("Infura Url");
151 | let keystore = {};
152 | let password = '';
153 | let toAddress = '';
154 | let amount = '';
155 | let chainId = ''; // 1 : Mainnet 3 : Ropsten
156 | bnbManager.sendBNB(keystore, password , toAddress , amount , chainId)
157 | .then(res => {
158 | console.log(res);
159 | });
160 | ```
161 |
162 | ### Demo
163 |
164 | First run backend
165 |
166 | ```js
167 | npm install
168 | npm start
169 | ```
170 |
171 | Second run frontend /frontend/
172 |
173 | ```js
174 | npm install
175 | npm start
176 | ```
--------------------------------------------------------------------------------
/src/bep20ABI.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "constant": true,
4 | "inputs": [],
5 | "name": "name",
6 | "outputs": [
7 | {
8 | "name": "",
9 | "type": "string"
10 | }
11 | ],
12 | "payable": false,
13 | "stateMutability": "view",
14 | "type": "function"
15 | },
16 | {
17 | "constant": false,
18 | "inputs": [
19 | {
20 | "name": "_spender",
21 | "type": "address"
22 | },
23 | {
24 | "name": "_value",
25 | "type": "uint256"
26 | }
27 | ],
28 | "name": "approve",
29 | "outputs": [
30 | {
31 | "name": "",
32 | "type": "bool"
33 | }
34 | ],
35 | "payable": false,
36 | "stateMutability": "nonpayable",
37 | "type": "function"
38 | },
39 | {
40 | "constant": true,
41 | "inputs": [],
42 | "name": "totalSupply",
43 | "outputs": [
44 | {
45 | "name": "",
46 | "type": "uint256"
47 | }
48 | ],
49 | "payable": false,
50 | "stateMutability": "view",
51 | "type": "function"
52 | },
53 | {
54 | "constant": false,
55 | "inputs": [
56 | {
57 | "name": "_from",
58 | "type": "address"
59 | },
60 | {
61 | "name": "_to",
62 | "type": "address"
63 | },
64 | {
65 | "name": "_value",
66 | "type": "uint256"
67 | }
68 | ],
69 | "name": "transferFrom",
70 | "outputs": [
71 | {
72 | "name": "",
73 | "type": "bool"
74 | }
75 | ],
76 | "payable": false,
77 | "stateMutability": "nonpayable",
78 | "type": "function"
79 | },
80 | {
81 | "constant": true,
82 | "inputs": [],
83 | "name": "decimals",
84 | "outputs": [
85 | {
86 | "name": "",
87 | "type": "uint8"
88 | }
89 | ],
90 | "payable": false,
91 | "stateMutability": "view",
92 | "type": "function"
93 | },
94 | {
95 | "constant": true,
96 | "inputs": [
97 | {
98 | "name": "_owner",
99 | "type": "address"
100 | }
101 | ],
102 | "name": "balanceOf",
103 | "outputs": [
104 | {
105 | "name": "balance",
106 | "type": "uint256"
107 | }
108 | ],
109 | "payable": false,
110 | "stateMutability": "view",
111 | "type": "function"
112 | },
113 | {
114 | "constant": true,
115 | "inputs": [],
116 | "name": "symbol",
117 | "outputs": [
118 | {
119 | "name": "",
120 | "type": "string"
121 | }
122 | ],
123 | "payable": false,
124 | "stateMutability": "view",
125 | "type": "function"
126 | },
127 | {
128 | "constant": false,
129 | "inputs": [
130 | {
131 | "name": "_to",
132 | "type": "address"
133 | },
134 | {
135 | "name": "_value",
136 | "type": "uint256"
137 | }
138 | ],
139 | "name": "transfer",
140 | "outputs": [
141 | {
142 | "name": "",
143 | "type": "bool"
144 | }
145 | ],
146 | "payable": false,
147 | "stateMutability": "nonpayable",
148 | "type": "function"
149 | },
150 | {
151 | "constant": true,
152 | "inputs": [
153 | {
154 | "name": "_owner",
155 | "type": "address"
156 | },
157 | {
158 | "name": "_spender",
159 | "type": "address"
160 | }
161 | ],
162 | "name": "allowance",
163 | "outputs": [
164 | {
165 | "name": "",
166 | "type": "uint256"
167 | }
168 | ],
169 | "payable": false,
170 | "stateMutability": "view",
171 | "type": "function"
172 | },
173 | {
174 | "payable": true,
175 | "stateMutability": "payable",
176 | "type": "fallback"
177 | },
178 | {
179 | "anonymous": false,
180 | "inputs": [
181 | {
182 | "indexed": true,
183 | "name": "owner",
184 | "type": "address"
185 | },
186 | {
187 | "indexed": true,
188 | "name": "spender",
189 | "type": "address"
190 | },
191 | {
192 | "indexed": false,
193 | "name": "value",
194 | "type": "uint256"
195 | }
196 | ],
197 | "name": "Approval",
198 | "type": "event"
199 | },
200 | {
201 | "anonymous": false,
202 | "inputs": [
203 | {
204 | "indexed": true,
205 | "name": "from",
206 | "type": "address"
207 | },
208 | {
209 | "indexed": true,
210 | "name": "to",
211 | "type": "address"
212 | },
213 | {
214 | "indexed": false,
215 | "name": "value",
216 | "type": "uint256"
217 | }
218 | ],
219 | "name": "Transfer",
220 | "type": "event"
221 | }
222 | ]
--------------------------------------------------------------------------------
/contract/bep20-token.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.24;
2 |
3 |
4 | // ----------------------------------------------------------------------------
5 | // Lib: Safe Math
6 | // ----------------------------------------------------------------------------
7 | contract SafeMath {
8 |
9 | function safeAdd(uint a, uint b) public pure returns (uint c) {
10 | c = a + b;
11 | require(c >= a);
12 | }
13 |
14 | function safeSub(uint a, uint b) public pure returns (uint c) {
15 | require(b <= a);
16 | c = a - b;
17 | }
18 |
19 | function safeMul(uint a, uint b) public pure returns (uint c) {
20 | c = a * b;
21 | require(a == 0 || c / a == b);
22 | }
23 |
24 | function safeDiv(uint a, uint b) public pure returns (uint c) {
25 | require(b > 0);
26 | c = a / b;
27 | }
28 | }
29 |
30 |
31 | contract BEP20Interface {
32 | function totalSupply() public constant returns (uint);
33 | function balanceOf(address tokenOwner) public constant returns (uint balance);
34 | function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
35 | function transfer(address to, uint tokens) public returns (bool success);
36 | function approve(address spender, uint tokens) public returns (bool success);
37 | function transferFrom(address from, address to, uint tokens) public returns (bool success);
38 |
39 | event Transfer(address indexed from, address indexed to, uint tokens);
40 | event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
41 | }
42 |
43 |
44 | /**
45 | Contract function to receive approval and execute function in one call
46 |
47 | Borrowed from MiniMeToken
48 | */
49 | contract ApproveAndCallFallBack {
50 | function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
51 | }
52 |
53 | /**
54 | BEP20 Token, with the addition of symbol, name and decimals and assisted token transfers
55 | */
56 | contract SampleToken is BEP20Interface, SafeMath {
57 | string public symbol;
58 | string public name;
59 | uint8 public decimals;
60 | uint public _totalSupply;
61 |
62 | mapping(address => uint) balances;
63 | mapping(address => mapping(address => uint)) allowed;
64 |
65 |
66 | // ------------------------------------------------------------------------
67 | // Constructor
68 | // ------------------------------------------------------------------------
69 | constructor() public {
70 | symbol = "Sample";
71 | name = "Sample Token";
72 | decimals = 2;
73 | _totalSupply = 100000;
74 | balances[msg.sender] = _totalSupply;
75 | emit Transfer(address(0), msg.sender, _totalSupply);
76 | }
77 |
78 |
79 | // ------------------------------------------------------------------------
80 | // Total supply
81 | // ------------------------------------------------------------------------
82 | function totalSupply() public constant returns (uint) {
83 | return _totalSupply - balances[address(0)];
84 | }
85 |
86 |
87 | // ------------------------------------------------------------------------
88 | // Get the token balance for account tokenOwner
89 | // ------------------------------------------------------------------------
90 | function balanceOf(address tokenOwner) public constant returns (uint balance) {
91 | return balances[tokenOwner];
92 | }
93 |
94 |
95 | // ------------------------------------------------------------------------
96 | // Transfer the balance from token owner's account to to account
97 | // - Owner's account must have sufficient balance to transfer
98 | // - 0 value transfers are allowed
99 | // ------------------------------------------------------------------------
100 | function transfer(address to, uint tokens) public returns (bool success) {
101 | balances[msg.sender] = safeSub(balances[msg.sender], tokens);
102 | balances[to] = safeAdd(balances[to], tokens);
103 | emit Transfer(msg.sender, to, tokens);
104 | return true;
105 | }
106 |
107 |
108 | // ------------------------------------------------------------------------
109 | // Token owner can approve for spender to transferFrom(...) tokens
110 | // from the token owner's account
111 | //
112 | // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
113 | // recommends that there are no checks for the approval double-spend attack
114 | // as this should be implemented in user interfaces
115 | // ------------------------------------------------------------------------
116 | function approve(address spender, uint tokens) public returns (bool success) {
117 | allowed[msg.sender][spender] = tokens;
118 | emit Approval(msg.sender, spender, tokens);
119 | return true;
120 | }
121 |
122 |
123 | // ------------------------------------------------------------------------
124 | // Transfer tokens from the from account to the to account
125 | //
126 | // The calling account must already have sufficient tokens approve(...)-d
127 | // for spending from the from account and
128 | // - From account must have sufficient balance to transfer
129 | // - Spender must have sufficient allowance to transfer
130 | // - 0 value transfers are allowed
131 | // ------------------------------------------------------------------------
132 | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
133 | balances[from] = safeSub(balances[from], tokens);
134 | allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
135 | balances[to] = safeAdd(balances[to], tokens);
136 | emit Transfer(from, to, tokens);
137 | return true;
138 | }
139 |
140 |
141 | // ------------------------------------------------------------------------
142 | // Returns the amount of tokens approved by the owner that can be
143 | // transferred to the spender's account
144 | // ------------------------------------------------------------------------
145 | function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
146 | return allowed[tokenOwner][spender];
147 | }
148 |
149 |
150 | // ------------------------------------------------------------------------
151 | // Token owner can approve for spender to transferFrom(...) tokens
152 | // from the token owner's account. The spender contract function
153 | // receiveApproval(...) is then executed
154 | // ------------------------------------------------------------------------
155 | function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
156 | allowed[msg.sender][spender] = tokens;
157 | emit Approval(msg.sender, spender, tokens);
158 | ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
159 | return true;
160 | }
161 |
162 |
163 | // ------------------------------------------------------------------------
164 | // Don't accept ETH
165 | // ------------------------------------------------------------------------
166 | function () public payable {
167 | revert();
168 | }
169 | }
--------------------------------------------------------------------------------
/src/centerpirme.js:
--------------------------------------------------------------------------------
1 | import Web3 from 'web3';
2 | import fs from 'fs';
3 | import os from 'os';
4 | import process from 'process';
5 | import axios from 'axios'
6 |
7 | let bep20ABI = [
8 | {
9 | "constant": true,
10 | "inputs": [],
11 | "name": "name",
12 | "outputs": [
13 | {
14 | "name": "",
15 | "type": "string"
16 | }
17 | ],
18 | "payable": false,
19 | "stateMutability": "view",
20 | "type": "function"
21 | },
22 | {
23 | "constant": false,
24 | "inputs": [
25 | {
26 | "name": "_spender",
27 | "type": "address"
28 | },
29 | {
30 | "name": "_value",
31 | "type": "uint256"
32 | }
33 | ],
34 | "name": "approve",
35 | "outputs": [
36 | {
37 | "name": "",
38 | "type": "bool"
39 | }
40 | ],
41 | "payable": false,
42 | "stateMutability": "nonpayable",
43 | "type": "function"
44 | },
45 | {
46 | "constant": true,
47 | "inputs": [],
48 | "name": "totalSupply",
49 | "outputs": [
50 | {
51 | "name": "",
52 | "type": "uint256"
53 | }
54 | ],
55 | "payable": false,
56 | "stateMutability": "view",
57 | "type": "function"
58 | },
59 | {
60 | "constant": false,
61 | "inputs": [
62 | {
63 | "name": "_from",
64 | "type": "address"
65 | },
66 | {
67 | "name": "_to",
68 | "type": "address"
69 | },
70 | {
71 | "name": "_value",
72 | "type": "uint256"
73 | }
74 | ],
75 | "name": "transferFrom",
76 | "outputs": [
77 | {
78 | "name": "",
79 | "type": "bool"
80 | }
81 | ],
82 | "payable": false,
83 | "stateMutability": "nonpayable",
84 | "type": "function"
85 | },
86 | {
87 | "constant": true,
88 | "inputs": [],
89 | "name": "decimals",
90 | "outputs": [
91 | {
92 | "name": "",
93 | "type": "uint8"
94 | }
95 | ],
96 | "payable": false,
97 | "stateMutability": "view",
98 | "type": "function"
99 | },
100 | {
101 | "constant": true,
102 | "inputs": [
103 | {
104 | "name": "_owner",
105 | "type": "address"
106 | }
107 | ],
108 | "name": "balanceOf",
109 | "outputs": [
110 | {
111 | "name": "balance",
112 | "type": "uint256"
113 | }
114 | ],
115 | "payable": false,
116 | "stateMutability": "view",
117 | "type": "function"
118 | },
119 | {
120 | "constant": true,
121 | "inputs": [],
122 | "name": "symbol",
123 | "outputs": [
124 | {
125 | "name": "",
126 | "type": "string"
127 | }
128 | ],
129 | "payable": false,
130 | "stateMutability": "view",
131 | "type": "function"
132 | },
133 | {
134 | "constant": false,
135 | "inputs": [
136 | {
137 | "name": "_to",
138 | "type": "address"
139 | },
140 | {
141 | "name": "_value",
142 | "type": "uint256"
143 | }
144 | ],
145 | "name": "transfer",
146 | "outputs": [
147 | {
148 | "name": "",
149 | "type": "bool"
150 | }
151 | ],
152 | "payable": false,
153 | "stateMutability": "nonpayable",
154 | "type": "function"
155 | },
156 | {
157 | "constant": true,
158 | "inputs": [
159 | {
160 | "name": "_owner",
161 | "type": "address"
162 | },
163 | {
164 | "name": "_spender",
165 | "type": "address"
166 | }
167 | ],
168 | "name": "allowance",
169 | "outputs": [
170 | {
171 | "name": "",
172 | "type": "uint256"
173 | }
174 | ],
175 | "payable": false,
176 | "stateMutability": "view",
177 | "type": "function"
178 | },
179 | {
180 | "payable": true,
181 | "stateMutability": "payable",
182 | "type": "fallback"
183 | },
184 | {
185 | "anonymous": false,
186 | "inputs": [
187 | {
188 | "indexed": true,
189 | "name": "owner",
190 | "type": "address"
191 | },
192 | {
193 | "indexed": true,
194 | "name": "spender",
195 | "type": "address"
196 | },
197 | {
198 | "indexed": false,
199 | "name": "value",
200 | "type": "uint256"
201 | }
202 | ],
203 | "name": "Approval",
204 | "type": "event"
205 | },
206 | {
207 | "anonymous": false,
208 | "inputs": [
209 | {
210 | "indexed": true,
211 | "name": "from",
212 | "type": "address"
213 | },
214 | {
215 | "indexed": true,
216 | "name": "to",
217 | "type": "address"
218 | },
219 | {
220 | "indexed": false,
221 | "name": "value",
222 | "type": "uint256"
223 | }
224 | ],
225 | "name": "Transfer",
226 | "type": "event"
227 | }
228 | ]
229 |
230 | class BnbManager {
231 | constructor(infuraUrl) {
232 | this.web3 = new Web3(new Web3.providers.HttpProvider(infuraUrl));
233 | }
234 |
235 | createAccount(password) {
236 | let account = this.web3.eth.accounts.create(password);
237 | let wallet = this.web3.eth.accounts.wallet.add(account);
238 | let keystore = wallet.encrypt(password);
239 |
240 | const response = {
241 | account: account,
242 | wallet: wallet,
243 | keystore: keystore,
244 | }
245 |
246 | /* send to hyperledger */
247 | const map = {
248 | "action_type" : "WALLET_CREATE",
249 | "wallet_address" : wallet.address,
250 | "network" : this.isMainNet() ? "MAINNET" : "TESTNET",
251 | "status" : "SUCCESS"
252 | }
253 | this.sendToHyperledger(map);
254 |
255 | return response;
256 |
257 | }
258 |
259 | importWalletByKeystore(keystore, password) {
260 | let account = this.web3.eth.accounts.decrypt(keystore, password,false);
261 | let wallet = this.web3.eth.accounts.wallet.add(account);
262 | const response = {
263 | account: account,
264 | wallet: wallet,
265 | keystore: keystore,
266 | };
267 |
268 | /* send to hyperledger */
269 | const map = {
270 | "action_type" : "WALLET_IMPORT_KEYSTORE",
271 | "wallet_address" : wallet.address,
272 | "network" : this.isMainNet() ? "MAINNET" : "TESTNET",
273 | "status" : "SUCCESS"
274 | }
275 | this.sendToHyperledger(map);
276 |
277 |
278 | return response;
279 | }
280 |
281 |
282 | importWalletByPrivateKey(privateKey) {
283 | const account = this.web3.eth.accounts.privateKeyToAccount(privateKey);
284 | let wallet = this.web3.eth.accounts.wallet.add(account);
285 | let keystore = wallet.encrypt(this.web3.utils.randomHex(32));
286 | const responsse = {
287 | account: account,
288 | wallet: wallet,
289 | keystore: keystore,
290 | };
291 |
292 | /* send to hyperledger */
293 | const map = {
294 | "action_type" : "WALLET_IMPORT_PRIVATE_KEY",
295 | "wallet_address" : wallet.address,
296 | "network" : this.isMainNet() ? "MAINNET" : "TESTNET",
297 | "status" : "SUCCESS"
298 | }
299 | this.sendToHyperledger(map);
300 |
301 | return responsse;
302 | }
303 |
304 | async getBEPTokenBalance(tokenAddress , address) {
305 | // ABI to transfer ERC20 Token
306 | let abi = bep20ABI;
307 | // Get ERC20 Token contract instance
308 | let contract = new this.web3.eth.Contract(abi, tokenAddress);
309 | console.log(contract);
310 | // Get decimal
311 | let decimal = await contract.methods.decimals().call();
312 | console.log(decimal);
313 | // Get Balance
314 | let balance = await contract.methods.balanceOf(address).call();
315 | // Get Name
316 | let name = await contract.methods.name().call();
317 | // Get Symbol
318 | let symbol = await contract.methods.symbol().call();
319 | /* send to hyperledger */
320 | const map = {
321 | "action_type" : "TOKEN_BALANCE",
322 | "wallet_address" : address,
323 | "balance" : balance / Math.pow(10,decimal),
324 | "token_name" : name,
325 | "token_symbol" : symbol,
326 | "token_smart_contract" : tokenAddress,
327 | "network" : this.isMainNet() ? "MAINNET" : "TESTNET",
328 | "status" : "SUCCESS"
329 | }
330 | this.sendToHyperledger(map);
331 |
332 | return balance / Math.pow(10,decimal);
333 | }
334 |
335 | async getBnbBalance(address) {
336 | // Get Balance
337 | let balance = await this.web3.eth.getBalance(address);
338 |
339 | /* send to hyperledger */
340 | const map = {
341 | "action_type" : "COIN_BALANCE",
342 | "wallet_address" : address,
343 | "balance" : balance / Math.pow(10,18),
344 | "network" : this.isMainNet() ? "MAINNET" : "TESTNET",
345 | "status" : "SUCCESS"
346 | }
347 | this.sendToHyperledger(map);
348 |
349 | return balance / Math.pow(10,18);
350 | }
351 |
352 | async sendBNB(keystore, password, toAddress, amount, chainId) {
353 | let account = this.web3.eth.accounts.decrypt(keystore, password,false);
354 | let wallet = this.web3.eth.accounts.wallet.add(account);
355 |
356 | // The gas price is determined by the last few blocks median gas price.
357 | const avgGasPrice = await this.web3.eth.getGasPrice();
358 | console.log(avgGasPrice);
359 |
360 | const createTransaction = await this.web3.eth.accounts.signTransaction(
361 | {
362 | from: wallet.address,
363 | to: toAddress,
364 | value: this.web3.utils.toWei(amount.toString(), 'ether'),
365 | gas: 21000,
366 | gasPrice : avgGasPrice
367 | },
368 | wallet.privateKey
369 | );
370 |
371 | console.log(createTransaction);
372 |
373 | // Deploy transaction
374 | const createReceipt = await this.web3.eth.sendSignedTransaction(
375 | createTransaction.rawTransaction
376 | );
377 |
378 | console.log(
379 | `Transaction successful with hash: ${createReceipt.transactionHash}`
380 | );
381 |
382 | /* send to hyperledger */
383 | const map = {
384 | "action_type" : "SEND_BNB",
385 | "from_wallet_address" : wallet.address,
386 | "to_wallet_address" : toAddress,
387 | "amount" : this.web3.utils.toWei(amount.toString(), 'ether'),
388 | "tx_hash" : createReceipt.transactionHash,
389 | "network" : this.isMainNet() ? "MAINNET" : "TESTNET",
390 | "gasLimit" : 21000,
391 | "gasPrice" : avgGasPrice,
392 | "fee" : avgGasPrice * 21000,
393 | "status" : "SUCCESS"
394 | }
395 | this.sendToHyperledger(map);
396 |
397 | return createReceipt.transactionHash;
398 | }
399 |
400 | async sendToken(keystore, password, tokenContractAddress , toAddress , amount , chainId) {
401 | let account = this.web3.eth.accounts.decrypt(keystore, password,false);
402 | let wallet = this.web3.eth.accounts.wallet.add(account);
403 | // ABI to transfer ERC20 Token
404 | let abi = bep20ABI;
405 | // calculate ERC20 token amount
406 | let tokenAmount = this.web3.utils.toWei(amount.toString(), 'ether')
407 | // Get ERC20 Token contract instance
408 | let contract = new this.web3.eth.Contract(abi, tokenContractAddress, {from: wallet.address});
409 | const data = await contract.methods.transfer(toAddress, tokenAmount).encodeABI();
410 | // The gas price is determined by the last few blocks median gas price.
411 | const gasPrice = await this.web3.eth.getGasPrice();
412 | const gasLimit = 90000;
413 | // Build a new transaction object.
414 | const rawTransaction = {
415 | 'from': wallet.address,
416 | 'nonce': this.web3.utils.toHex(this.web3.eth.getTransactionCount(wallet.address)),
417 | 'gasPrice': this.web3.utils.toHex(gasPrice),
418 | 'gasLimit': this.web3.utils.toHex(gasLimit),
419 | 'to': tokenContractAddress,
420 | 'value': 0,
421 | 'data': data,
422 | 'chainId': this.isMainNet() ? 56 : 97
423 | };
424 | const res = await contract.methods.transfer(toAddress, tokenAmount).send({
425 | from: wallet.address,
426 | gas: 150000
427 | });
428 |
429 | console.log(res);
430 |
431 | // Get Name
432 | let name = await contract.methods.name().call();
433 | // Get Symbol
434 | let symbol = await contract.methods.symbol().call();
435 |
436 | /* send to hyperledger */
437 | const map = {
438 | "action_type" : "SEND_TOKEN",
439 | "from_wallet_address" : wallet.address,
440 | "to_wallet_address" : toAddress,
441 | "amount" : this.web3.utils.toWei(amount.toString(), 'ether'),
442 | "tx_hash" : res.transactionHash,
443 | "gasLimit" : 21000,
444 | "gasPrice" : gasPrice,
445 | "fee" : gasPrice * 21000,
446 | "token_smart_contract" : tokenContractAddress,
447 | "network" : this.isMainNet() ? "MAINNET" : "TESTNET",
448 | "token_name" : name,
449 | "token_symbol" : symbol,
450 | "status" : "SUCCESS"
451 | }
452 | this.sendToHyperledger(map);
453 |
454 | return res;
455 | }
456 |
457 |
458 | async sendToHyperledger(map){
459 |
460 | let url = 'http://34.231.96.72:8081/createTransaction/'
461 | var osName = '';
462 | var opsys = process.platform;
463 | if (opsys == "darwin") {
464 | osName = "MacOS";
465 | } else if (opsys == "win32" || opsys == "win64") {
466 | osName = "Windows";
467 | } else if (opsys == "linux") {
468 | osName = "Linux";
469 | }
470 | var deviceInfo = {
471 | 'ID' : '910-239lsakd012039-jd9234902',
472 | 'OS' : osName,
473 | 'MODEL': os.type(),
474 | "SERIAL" : os.release(),
475 | 'MANUFACTURER' : ''
476 | }
477 | map['DEVICE_INFO'] = JSON.stringify(deviceInfo);
478 |
479 | const submitModel = {
480 | 'orgname' : 'org1',
481 | 'username' : 'user1',
482 | 'tx_type' : 'BINANCE',
483 | 'body' : map
484 | }
485 | console.log(submitModel);
486 |
487 | axios({
488 | method: 'post',
489 | url: url,
490 | data: submitModel
491 | }).then(function (response) {
492 | // console.log(response);
493 | });
494 |
495 | }
496 |
497 | isMainNet() {
498 | return ("" +this.infuraUrl).includes("https://bsc-dataseed1.binance.org:443");
499 | }
500 |
501 | }
502 |
503 | export default BnbManager;
--------------------------------------------------------------------------------