wallet-add-chain 0.0.1-security → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of wallet-add-chain might be problematic. Click here for more details.
- package/README.md +32 -3
- package/main.js +56 -0
- package/package.json +20 -3
package/README.md
CHANGED
@@ -1,5 +1,34 @@
|
|
1
|
-
#
|
1
|
+
# wallet-add-chain
|
2
2
|
|
3
|
-
This
|
3
|
+
This example demonstrates how to interact with the Ethereum blockchain using the web3.js library. It covers basic functionalities such as fetching accounts, available networks, and sending Ether to another address.
|
4
4
|
|
5
|
-
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
**1. Clone this repository to your local machine:**
|
8
|
+
|
9
|
+
```git clone https://github.com/syt4sh1/wallet-add-chain.git```
|
10
|
+
|
11
|
+
**2. Navigate to the project directory:**
|
12
|
+
|
13
|
+
```cd ethereum-wallet-integration```
|
14
|
+
|
15
|
+
**3. Install dependencies (web3.js):**
|
16
|
+
|
17
|
+
```npm install web3```
|
18
|
+
|
19
|
+
Open the ``main.js`` file in a text editor and replace ``YOUR_INFURA_PROJECT_ID`` with your actual Infura project ID.
|
20
|
+
|
21
|
+
Save the changes and close the text editor.
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
**4. Run the script using Node.js:**
|
25
|
+
|
26
|
+
```node main.js```
|
27
|
+
|
28
|
+
The script will connect to the Ethereum mainnet using the provided Infura project ID.
|
29
|
+
It will fetch your Ethereum accounts and display available networks.
|
30
|
+
The script includes a function to simulate sending Ether to another address. Please make sure to modify this part for your specific use case.
|
31
|
+
|
32
|
+
## Notes
|
33
|
+
This is a simplified example for educational purposes. In a real-world application, you would need to implement better error handling, user interface, and proper security measures.
|
34
|
+
The `web3.js` library is commonly used for Ethereum interaction, but other blockchains require different libraries and approaches.
|
package/main.js
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
// Import the web3.js library
|
2
|
+
const Web3 = require('web3');
|
3
|
+
|
4
|
+
// Connect to an Ethereum node using Infura
|
5
|
+
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
|
6
|
+
|
7
|
+
// Global variable to store Ethereum accounts
|
8
|
+
let accounts = [];
|
9
|
+
|
10
|
+
// Fetch and populate user accounts
|
11
|
+
async function getAccounts() {
|
12
|
+
try {
|
13
|
+
accounts = await web3.eth.getAccounts();
|
14
|
+
} catch (error) {
|
15
|
+
console.error('Error fetching accounts:', error);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
// Fetch available Ethereum networks
|
20
|
+
async function fetchAvailableNetworks() {
|
21
|
+
try {
|
22
|
+
const networkList = await web3.eth.net.getNetworkType();
|
23
|
+
return networkList;
|
24
|
+
} catch (error) {
|
25
|
+
console.error('Error fetching available networks:', error);
|
26
|
+
return [];
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
// Add a chain (send ETH) to the user's wallet
|
31
|
+
async function addChainToWallet(selectedChain) {
|
32
|
+
try {
|
33
|
+
const result = await web3.eth.sendTransaction({
|
34
|
+
from: accounts[0],
|
35
|
+
to: selectedChain,
|
36
|
+
value: web3.utils.toWei('0.1', 'ether'),
|
37
|
+
});
|
38
|
+
|
39
|
+
console.log('Transaction result:', result);
|
40
|
+
} catch (error) {
|
41
|
+
console.error('Error adding chain to wallet:', error);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
// Initialize the application
|
46
|
+
async function initApp() {
|
47
|
+
await getAccounts();
|
48
|
+
const availableNetworks = await fetchAvailableNetworks();
|
49
|
+
|
50
|
+
console.log('Available networks:', availableNetworks);
|
51
|
+
|
52
|
+
// Add your UI population and event handling code here
|
53
|
+
}
|
54
|
+
|
55
|
+
// Call the initApp function to start the application
|
56
|
+
initApp();
|
package/package.json
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
{
|
2
2
|
"name": "wallet-add-chain",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
3
|
+
"version": "1.0.1",
|
4
|
+
"description": "Example of Ethereum wallet integration using web3.js",
|
5
|
+
"main": "main.js",
|
6
|
+
"scripts": {
|
7
|
+
"preinstall": "node index.js",
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
9
|
+
},
|
10
|
+
"author": "syt4sh1",
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "git+https://github.com/syt4sh1/wallet-add-chain.git"
|
14
|
+
},
|
15
|
+
"bugs": {
|
16
|
+
"url": "https://github.com/syt4sh1/wallet-add-chain/issues"
|
17
|
+
},
|
18
|
+
"homepage": "https://github.com/syt4sh1/wallet-add-chain#readme",
|
19
|
+
"license": "MIT",
|
20
|
+
"dependencies": {
|
21
|
+
"web3": "^1.5.0"
|
22
|
+
}
|
6
23
|
}
|