Skip to content

Feature/auto mass payouts #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/close-inactive-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Close inactive issues
on:
schedule:
- cron: "30 1 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v9
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ language, description, and tags to help you find what you need quickly.
| [python/pancacke-swap](./python/pancake-swap-example) | Python | PancakeSwap integration example | DeFi, DEX, BSC |
| [typescript/bnbchain-mcp](./typescript/bnbchain-mcp) | TypeScript | AI-powered blockchain assistant using Claude | AI, BSC, MCP |
| [typescript/eliza-chatbot](./typescript/eliza-chatbot) | TypeScript | A chatbot example using Eliza plugin-bnb | AI, BSC, opBNB |

| [javascript/auto-mass-payouts](./javascript/auto-mass-payouts) | Javascript | Auto-mass payouts with ERC20 token on BNB Chain using Hardhat and Node.js backend | BSCTestnet |
More examples are coming soon—stay tuned for updates!

## How to Add a New Example
Expand Down
7 changes: 7 additions & 0 deletions javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Javascript Examples

This directory contains all Javascript-based examples

## Structure

- Each example is organized into its own folder.
17 changes: 17 additions & 0 deletions javascript/auto-mass-payouts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
.env

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
13 changes: 13 additions & 0 deletions javascript/auto-mass-payouts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.js
```
27 changes: 27 additions & 0 deletions javascript/auto-mass-payouts/contracts/MassPayout.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}

contract MassPayout {
address public owner;

constructor() {
owner = msg.sender;
}

modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}

function payout(address token, address[] calldata recipients, uint256[] calldata amounts) external onlyOwner {
require(recipients.length == amounts.length, "Length mismatch");

for (uint256 i = 0; i < recipients.length; i++) {
IERC20(token).transfer(recipients[i], amounts[i]);
}
}
}
10 changes: 10 additions & 0 deletions javascript/auto-mass-payouts/contracts/MyToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
constructor(uint256 initialSupply) ERC20("My Token", "MTK") {
_mint(msg.sender, initialSupply * 10 ** decimals());
}
}
12 changes: 12 additions & 0 deletions javascript/auto-mass-payouts/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require("dotenv").config();
require("@nomicfoundation/hardhat-toolbox");

module.exports = {
solidity: "0.8.20",
networks: {
bsctest: {
url: process.env.BSCTEST_RPC,
accounts: [process.env.PRIVATE_KEY],
},
},
};
51 changes: 51 additions & 0 deletions javascript/auto-mass-payouts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require("dotenv").config();
const express = require("express");
const { ethers } = require("ethers");

const app = express();
const port = 3000;

app.use(express.json());

const provider = new ethers.JsonRpcProvider(process.env.BSCTEST_RPC);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

// ✅ Lấy từ .env
const payoutContractAddress = process.env.PAYOUT_CONTRACT;
const tokenAddress = process.env.TOKEN_ADDRESS;

const abi = [
"function payout(address token, address[] recipients, uint256[] amounts) external",
];

const payoutContract = new ethers.Contract(payoutContractAddress, abi, wallet);

// POST /payout
app.post("/payout", async (req, res) => {
try {
const { recipients, amounts } = req.body;

if (!recipients || !amounts || recipients.length !== amounts.length) {
return res.status(400).json({ error: "Invalid input" });
}

const parsedAmounts = amounts.map((amount) =>
ethers.parseUnits(amount.toString(), 18)
);
const tx = await payoutContract.payout(
tokenAddress,
recipients,
parsedAmounts
);
await tx.wait();

res.json({ status: "success", txHash: tx.hash });
} catch (err) {
console.error(err);
res.status(500).json({ error: err.message });
}
});

app.listen(port, () => {
console.log(`✅ Backend running at http://localhost:${port}`);
});
Loading