simple multisender site

This commit is contained in:
2025-09-01 17:54:38 +09:00
parent 2616d1d18b
commit b455d5699a
14 changed files with 578 additions and 17639 deletions

2
.gitignore vendored
View File

@@ -4,6 +4,8 @@
/node_modules /node_modules
/.pnp /.pnp
.pnp.js .pnp.js
.env
package-lock.json
# testing # testing
/coverage /coverage

View File

@@ -28,43 +28,3 @@ The build is minified and the filenames include the hashes.\
Your app is ready to be deployed! Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
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.
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.
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.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
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)
### Analyzing the Bundle Size
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)
### Making a Progressive Web App
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)
### Advanced Configuration
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)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
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)

17534
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,10 +7,12 @@
"@testing-library/jest-dom": "^6.6.3", "@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0", "@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"ethers": "^6.15.0",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4",
"xlsx": "^0.18.5"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

View File

@@ -2,14 +2,8 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!-- <!--
manifest.json provides metadata used when your web app is installed on a manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
@@ -24,10 +18,9 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>React App</title> <title>Admin MultiSender</title>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div> <div id="root"></div>
<!-- <!--
This HTML file is a template. This HTML file is a template.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -1,23 +1,6 @@
{ {
"short_name": "React App", "short_name": "React App",
"name": "Create React App Sample", "name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".", "start_url": ".",
"display": "standalone", "display": "standalone",
"theme_color": "#000000", "theme_color": "#000000",

View File

@@ -1,25 +0,0 @@
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;

261
src/App.jsx Normal file
View File

@@ -0,0 +1,261 @@
import './App.css';
import { read, utils } from "xlsx";
import { ethers, formatEther, parseEther } from "ethers";
import { useCallback, useEffect, useRef, useState } from 'react';
import { tokenAbi } from "./tokenAbi";
const contractAddress = "0x1ebA64fDe3BF54545c86B9e3bB40c72f50f8D012";
function App() {
const abi = [{"inputs": [{"internalType": "address","name": "token","type": "address"},{"internalType": "address[]","name": "addresses","type": "address[]"},{"internalType": "uint256[]","name": "amounts","type": "uint256[]"},{"internalType": "bool","name": "isToken","type": "bool"}],"name": "batchTransferFrom","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "payable","type": "function"}]
const [from, setFrom] = useState("");
const [toArray, setToArray] = useState([]);
const [amountArray, setAmountArray] = useState([]);
const isToken = true;
const [provider, setProvider] = useState();
const [text, setText] = useState("파일 업로드")
const tokenRef = useRef(null);
const handleFile = (file) => {
if (!file) return;
setText(file.name);
const reader = new FileReader();
reader.onload = (evt) => {
try {
const data = new Uint8Array(evt.target.result);
const workbook = read(data, { type: 'array' });
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = utils.sheet_to_json(worksheet, {raw:true});
const filteredData = jsonData.filter(row => {
return (
typeof row.address === "string" &&
!row.address.toUpperCase().includes("EX") &&
!String(row.amount).toUpperCase().includes("EX")
);
});
const addresses = filteredData.map((row) => row.address);
const amount = filteredData.map((row) => {
// 소수점 2자리까지 반올림 처리
const rounded = Math.round(Number(row.amount) * 100) / 100;
return parseEther(rounded.toFixed(2));
});
setToArray(addresses);
setAmountArray(amount);
} catch (error) {
alert(error)
}
};
reader.readAsArrayBuffer(file);
};
const handleDrop = (e) => {
e.preventDefault();
const file = e.dataTransfer.files[0];
handleFile(file);
};
const handleFileChange = (e) => {
const file = e.target.files[0];
handleFile(file);
};
// const handleCheckboxChange = (e) => {
// setIsToken(e.target.checked);
// };
const handleDragOver = (e) => {
e.preventDefault();
};
useEffect(()=>{
if (!window.ethereum) return alert("MetaMask not installed");
setProvider(new ethers.BrowserProvider(window.ethereum))
},[])
const walletProvider = useCallback(async ()=>{
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x38' }] //0x38
});
} catch (err) {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x38', //0x38
chainName: 'BNB Smart Chain Mainnet',
rpcUrls: ['https://binance.llamarpc.com'],
nativeCurrency: {
name: 'BNB',
symbol: 'BNB',
decimals: 18
},
blockExplorerUrls: ['https://bscscan.com/']
}]
});
}
await provider.send("eth_requestAccounts", []);
window.ethereum.on("accountsChanged", (accounts) => {
if (accounts.length > 0) {
setFrom(accounts[0]);
} else {
setFrom(null);
}
});
const signer = provider.getSigner();
const senderAddress = await signer;
setFrom(senderAddress.address)
},[provider])
useEffect(()=>{
if(provider){
walletProvider()
}
return () => {
if (window.ethereum?.removeListener) {
window.ethereum.removeListener("accountsChanged", () => {});
window.ethereum.removeListener("chainChanged", () => {});
}
};
},[provider,walletProvider])
const sendToken = async () => {
const tokenAddress = tokenRef.current?.value;
let totalAmount = 0;
amountArray.map((row)=> totalAmount += parseFloat(formatEther(row)));
const signer = await provider.getSigner();
const contract = new ethers.Contract(contractAddress, abi, signer);
const batchSize = 200;
const loopCount = Math.ceil(toArray.length / batchSize);
let status;
if(toArray.length !== 0 && amountArray.length !== 0 && toArray.length === amountArray.length)
{
try {
const tokenContract = new ethers.Contract(tokenAddress, tokenAbi, signer);
let balance = isToken ? await tokenContract.balanceOf(from) : await provider.getBalance(from);
console.log(balance, parseEther(totalAmount.toString()))
if(balance >= parseEther(totalAmount.toString())){
if(isToken)
{
//token approve
const tx = await tokenContract.approve(
contractAddress,
parseEther(totalAmount.toString())
)
await provider.waitForTransaction(tx.hash);
}
} else {
throw new Error("잔액부족")
}
} catch (error) {
alert(error)
}
} else {
alert("양식이 맞지 않습니다.")
}
for (let i = 0; i < loopCount; i++)
{
const start = i * batchSize;
const end = start + batchSize;
const chunkAddresses = toArray.slice(start, end);
const chunkAmounts = amountArray.slice(start, end);
const chunkTotal = chunkAmounts.reduce((acc, amt) => acc + parseFloat(formatEther(amt)), 0);
console.log(tokenAddress, chunkAddresses, chunkAmounts, isToken,chunkTotal)
//multisender
try {
const tx = await contract.batchTransferFrom(
tokenAddress,
chunkAddresses,
chunkAmounts,
isToken,
{value : isToken ? 0 : parseEther(chunkTotal.toString())}
);
status = await provider.waitForTransaction(tx.hash);
} catch (error) {
alert(error)
}
}
if(status){
setText("파일 업로드")
setToArray([]);
setAmountArray([]);
}
};
return (
<div className="App">
<h1>Admin MultiSender</h1>
<div
style={{
width : "600px",
height : "100px",
margin : "0 Auto",
display : "flex",
flexDirection: "column",
}}
>
{/* <div>
<span style={{fontSize: "18px"}}>토큰 전송 </span>
<input type="checkbox" onChange={handleCheckboxChange} />
</div> */}
<div>
<span style={{fontSize: "18px"}}>토큰 컨트랙트 : </span>
<input type="text" ref={tokenRef} placeholder='' style={{fontSize: "18px", marginTop : "10px", width : "450px"}} defaultValue={"0x36b8dE7c6B06B3f170003452114f0B8E6BcFEE18"}/>
</div>
<div>
<span style={{fontSize: "18px"}}>보내는 계좌 : </span>
<input type='text' placeholder={from} style={{fontSize: "18px", marginTop : "10px", width: "450px", border: "none"}} disabled />
</div>
</div>
<input type="file" id="fileInput" style={{ display: "none" }} onChange={handleFileChange} />
<label htmlFor="fileInput">
<div
id="upload"
onDrop={handleDrop}
onDragOver={handleDragOver}
style={{
// display : toArray.length == 0 ? "block" : "none",
border: '2px dashed gray',
padding: '50px',
textAlign: 'center',
marginTop: '50px',
marginBottom: '20px',
margin: "0 Auto",
width: "200px"
}}
>
{text}
</div>
</label>
<button type='button' onClick={sendToken} style={{marginTop : "20px", padding: "8px", width: "100px", fontSize: "20px"}}>전송</button>
</div>
);
}
export default App;

View File

@@ -1,8 +0,0 @@
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import './index.css'; import './index.css';
import App from './App'; import App from './App.jsx';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root')); const root = ReactDOM.createRoot(document.getElementById('root'));

View File

@@ -1,5 +0,0 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

310
src/tokenAbi.js Normal file
View File

@@ -0,0 +1,310 @@
export const tokenAbi = [
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "allowance",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "needed",
"type": "uint256"
}
],
"name": "ERC20InsufficientAllowance",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "needed",
"type": "uint256"
}
],
"name": "ERC20InsufficientBalance",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "approver",
"type": "address"
}
],
"name": "ERC20InvalidApprover",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "receiver",
"type": "address"
}
],
"name": "ERC20InvalidReceiver",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
}
],
"name": "ERC20InvalidSender",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "ERC20InvalidSpender",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]