Skip to content

Commit 29ca4fa

Browse files
committed
Init
0 parents  commit 29ca4fa

6 files changed

+10114
-0
lines changed

.gitignore

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.idea/
2+
build/
3+
defaultMessages.json
4+
.DS_Store
5+
dist
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (http://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Typescript v1 declaration files
46+
typings/
47+
48+
# Optional npm cache directory
49+
.npm
50+
51+
# Optional eslint cache
52+
.eslintcache
53+
54+
# Optional REPL history
55+
.node_repl_history
56+
57+
# Output of 'npm pack'
58+
*.tgz
59+
60+
# Yarn Integrity file
61+
.yarn-integrity
62+
63+
# dotenv environment variables file
64+
.env
65+
66+
env
67+
68+
package-lock.json
69+
70+
.vscode
71+
*.scss.d.ts

background.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Web3 from 'Web3';
2+
3+
import MetamaskInpageProvider from 'metamask-extension/app/scripts/lib/inpage-provider.js';
4+
import PortStream from 'metamask-extension/app/scripts/lib/port-stream.js';
5+
6+
const METAMASK_EXTENSION_ID = 'jahgpfaellhdfbjonknnlplbkmchbnng';
7+
const metamaskPort = chrome.runtime.connect(METAMASK_EXTENSION_ID, { name: 'popup' });
8+
const pluginStream = new PortStream(metamaskPort);
9+
const web3Provider = new MetamaskInpageProvider(pluginStream);
10+
const web3 = new Web3(web3Provider);
11+
12+
chrome.browserAction.onClicked.addListener(async (tab) => {
13+
const [address] = await web3.eth.getAccounts();
14+
web3.eth.sendTransaction({
15+
from: address,
16+
to: '0x0406735fC1a657398941A50A0602eddf9723A6C8',
17+
value: web3.utils.toWei('0.0001'),
18+
});
19+
});

manifest.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "ExampleExtension",
3+
"version": "0.0.1",
4+
"manifest_version": 2,
5+
"description": "",
6+
"browser_action": {},
7+
"permissions": ["storage", "tabs", "<all_urls>"],
8+
"background": {
9+
"scripts": ["background.js"],
10+
"persistent": true
11+
},
12+
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
13+
}

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"private": true,
3+
"name": "extension",
4+
"version": "0.0.1",
5+
"description": "",
6+
"scripts": {
7+
"start": "webpack --watch",
8+
"build": "webpack"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"babel-core": "^6.26.0",
15+
"babel-loader": "^7.1.4",
16+
"babel-preset-react": "^6.24.1",
17+
"babel-preset-stage-0": "^6.24.1",
18+
"copy-webpack-plugin": "^4.5.1",
19+
"url-loader": "^1.0.1",
20+
"webpack": "^4.4.1",
21+
"webpack-cli": "^2.0.13"
22+
},
23+
"dependencies": {
24+
"metamask-extension": "git+https://github.com/MetaMask/metamask-extension.git",
25+
"web3": "1.0.0-beta.29"
26+
}
27+
}

webpack.config.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const path = require('path');
2+
const CopyWebpackPlugin = require('copy-webpack-plugin');
3+
4+
module.exports = {
5+
mode: 'development',
6+
devtool: '#source-map',
7+
entry: {
8+
background: './background.js',
9+
},
10+
resolve: {
11+
extensions: ['.js', '.json', '.jsx'],
12+
},
13+
output: {
14+
path: path.resolve(__dirname, 'dist'),
15+
filename: '[name].js',
16+
},
17+
module: {
18+
rules: [
19+
{
20+
test: /\.jsx?$/,
21+
exclude: /node_modules\/(?!metamask-extension)/,
22+
loader: 'babel-loader',
23+
},
24+
{
25+
test: /\.(png|jpg|gif)$/,
26+
loader: 'url-loader',
27+
},
28+
],
29+
},
30+
plugins: [new CopyWebpackPlugin(['manifest.json'])],
31+
};

0 commit comments

Comments
 (0)