-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUploadSong.js
33 lines (28 loc) · 1.43 KB
/
UploadSong.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React, { useState } from 'react';
import Web3 from 'web3';
import DecentralizedMusicMarketplace from '../artifacts/DecentralizedMusicMarketplace.json';
const UploadSong = () => {
const [title, setTitle] = useState('');
const [price, setPrice] = useState('');
const [songHash, setSongHash] = useState('');
const [account, setAccount] = useState('');
const upload = async () => {
const web3 = new Web3(window.ethereum);
const networkId = await web3.eth.net.getId();
const contractAddress = DecentralizedMusicMarketplace.networks[networkId].address;
const contract = new web3.eth.Contract(DecentralizedMusicMarketplace.abi, contractAddress);
await contract.methods.uploadSong(title, Web3.utils.toWei(price, 'ether'), songHash).send({ from: account });
alert('Song uploaded successfully!');
};
return (
<div>
<h2>Upload Song</h2>
<input type="text" placeholder="Your Ethereum Address" onChange={(e) => setAccount(e.target.value)} />
<input type="text" placeholder="Song Title" onChange={(e) => setTitle(e.target.value)} />
<input type="number" placeholder="Price in Ether" onChange={(e) => setPrice(e.target.value)} />
<input type="text" placeholder="Song Hash" onChange={(e) => setSongHash(e.target.value)} />
<button onClick={upload}>Upload</button>
</div>
);
};
export default UploadSong;