-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDonateToArtist.js
31 lines (26 loc) · 1.35 KB
/
DonateToArtist.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
import React, { useState } from 'react';
import Web3 from 'web3';
import DecentralizedMusicMarketplace from '../artifacts/DecentralizedMusicMarketplace.json';
const DonateToArtist = () => {
const [artistAddress, setArtistAddress] = useState('');
const [amount, setAmount] = useState('');
const [account, setAccount] = useState('');
const donate = 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.donateToArtist(artistAddress).send({ from: account, value: Web3.utils.toWei(amount, 'ether') });
alert('Donation made successfully!');
};
return (
<div>
<h2>Donate to Artist</h2>
<input type="text" placeholder="Your Ethereum Address" onChange={(e) => setAccount(e.target.value)} />
<input type="text" placeholder="Artist's Ethereum Address" onChange={(e) => setArtistAddress(e.target.value)} />
<input type="number" placeholder="Amount in Ether" onChange={(e) => setAmount(e.target.value)} />
<button onClick={donate}>Donate</button>
</div>
);
};
export default DonateToArtist;