返回顶部
g

giveaway-skills赠送技能

>

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
253
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

giveaway-skills

BSC 空投合约调用技能

1. 部署信息

  • - 网络: BSC (币安智能链主网, chainId = 56)
  • 合约文件: contracts/contracts/Giveaway.sol
  • 合约地址: 0xc9Db158004fEFe15633eF2Ac3C3eA209e58Db5B9
  • 主要依赖: IERC20, Ownable, ReentrancyGuard, 内部 TransferHelper 库

调用时的假设条件:

  • - 您已连接到 BSC 主网 RPC (例如 https://bsc-dataseed.binance.org)
  • 账户余额和 gas 设置由调用方处理

2. 核心枚举和结构体 (调用时以 uint 形式传入)

DistributionType

  • - 0 = AVERAGE: 平均分配,每次领取获得 amount / count
  • 1 = RANDOM: 随机分配,单次领取大致在 \(0 \sim 2 \times\) 平均值的范围内

ClaimRestriction

  • - 0 = PUBLIC: 公开,无额外限制
  • 1 = TOKEN_HOLDER: 仅限持有 restrictionToken 且余额 ≥ minTokenBalance 的地址
  • 2 = WHITELIST: 仅限白名单地址领取

GiveawayInfo

  • - token: 空投的代币地址,address(0) 表示 BNB
  • sender: 创建者地址
  • amount: 合约中当前剩余的空投总金额 (扣除创建费后)
  • count: 当前剩余的可领取名额
  • distributionType: 分配类型 (0/1)
  • restriction: 领取限制类型 (0/1/2)
  • restrictionToken: 限制代币地址 (仅 TOKEN_HOLDER 类型有意义)
  • minTokenBalance: 所需的最低代币余额
  • lastDate: 过期时间戳 (秒)

3. 写入函数速查表

3.1 创建空投 createGiveaway

签名:

solidity
function createGiveaway(
address token,
uint256 amount,
uint256 count,
DistributionType distributionType,
ClaimRestriction restriction,
address restrictionToken,
uint256 minTokenBalance,
string memory content,
uint256 lastDate
) public payable

关键约束:

  • - bytes(content).length < 128
  • amount > 0
  • amount / count > 0
  • distributionType ∈ {0,1}
  • restriction ∈ {0,1,2}
  • 如果 restriction == TOKEN_HOLDER (1):

- restrictionToken != address(0)
- minTokenBalance > 0

费用和转账:

  • - 费用: feeAmount = (amount / 1000) * FEERATE,直接发送至 FEEADDRESS
  • 实际进入合约的金额: sendAmount = amount - feeAmount
  • 如果 token == address(0) (BNB 空投):

- 交易 msg.value >= amount
- feeAmount 和 sendAmount 均以 BNB 支付
  • - 如果 token != address(0) (ERC20 空投):

- 交易 msg.value == 0
- 您必须先在链上执行 approve:
- approve(contract, amount) (用户 → 合约)
- 合约内部使用 safeTransferFrom 将 feeAmount 发送至 FEEADDRESS,将 sendAmount 发送至合约自身

3.2 领取空投 claimGiveaway

solidity
function claimGiveaway(uint256 id) public nonReentrant

内部检查:

  • - giveawayInfos[id].amount != 0: 空投存在且有剩余金额
  • 调用者尚未领取: giveawayInfoexist[id][msg.sender] == 0
  • 未过期: giveawayInfos[id].lastDate > block.timestamp
  • TOKENHOLDER: 检查 IERC20(restrictionToken).balanceOf(msg.sender) >= minTokenBalance
  • WHITELIST: giveawayWhitelist[id][msg.sender] == true

分配逻辑:

  • - AVERAGE:

- 如果 count == 1: 将所有剩余金额发送给当前领取者
- 否则,单次领取金额为 sendAmount = amount / count
  • - RANDOM:

- 如果 count == 1: 同样发送所有剩余金额
- 否则:
- randomNumber = uint8(keccak256(...)) % 100
- sendAmount = (amount / count 2) randomNumber / 100

3.3 提取过期空投 withdrawExpiredGiveaway

solidity
function withdrawExpiredGiveaway(uint256 id) public nonReentrant

约束:

  • - giveawayInfos[id].amount != 0
  • giveawayInfos[id].sender == msg.sender
  • giveawayInfos[id].lastDate < block.timestamp

提取费用:

  • - feeAmount = (amount / 1000) * EXPIREDRATE
  • sendAmount = amount - feeAmount
  • 转账逻辑同样区分 BNB 和 ERC20

3.4 白名单管理

solidity
function addToWhitelist(uint256 giveawayId, address[] memory addresses) public
function removeFromWhitelist(uint256 giveawayId, address[] memory addresses) public

约束:

  • - 仅限空投创建者: giveawayInfos[giveawayId].sender == msg.sender
  • 且空投类型必须为 WHITELIST: restriction == ClaimRestriction.WHITELIST

4. 读取函数速查表

solidity
function getGiveawayInfo(uint256 id) external view returns (GiveawayInfo memory)
function isInWhitelist(uint256 giveawayId, address user) external view returns (bool)
function canClaim(uint256 id, address user) external view returns (bool)

canClaim 的关键点:

  • - 如果金额为 0、已领取或 block.timestamp >= lastDate,则返回 false
  • TOKEN_HOLDER: 检查代币余额
  • WHITELIST: 检查白名单
  • 否则返回 true (PUBLIC)

5. 脚本/前端使用示例 (ethers.js)

假设您已有 provider / signer 并已加载编译后的 ABI:

ts
import { ethers } from ethers;
import GiveawayAbi from ../artifacts/contracts/Giveaway.sol/Giveaway.json;

const GIVEAWAY_ADDRESS = 0xc9Db158004fEFe15633eF2Ac3C3eA209e58Db5B9;

// 创建合约实例 (读取或写入)
export function getGiveawayContract(providerOrSigner: ethers.Signer | ethers.providers.Provider) {
return new ethers.Contract(GIVEAWAY_ADDRESS, GiveawayAbi.abi, providerOrSigner);
}

// 示例: 创建 BNB 空投
export async function createBnbGiveaway(
signer: ethers.Signer,
params: {
amountWei: ethers.BigNumberish;
count: number;
distributionType: 0 | 1;
restriction: 0 | 1 | 2;
restrictionToken: string;
minTokenBalance: ethers.BigNumberish;
content: string;
lastDate: number;
}
) {
const contract = getGiveawayContract(signer);
const tx = await contract.createGiveaway(
ethers.constants.AddressZero,
params.amountWei,
params.count,
params.distributionType,
params.restriction,
params.restrictionToken,
params.minTokenBalance,
params.content,
params.lastDate,
{ value: params.amountWei }
);
return tx.wait();
}

// 示例: 领取空投
export async function claimGiveaway(signer: ethers.Signer, id: number) {
const contract = getGiveawayContract(signer);
const tx = await contract.claimGiveaway(id);
return tx.wait();
}

在前端或脚本中集成时:

  • - 读取函数 (getGiveawayInfo, canClaim, isInWhitelist) 可使用 provider 实例;
  • 写入函数 (createGiveaway, claimGiveaway, withdrawExpiredGiveaway, 白名单添加/移除) 必须使用具有签名能力的 signer;
  • 对于 BNB 空投,您必须通过 value 传递等于 amount 的 BNB;对于 ERC20 空投,您必须事先执行 approve

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 giveaway-skills-1776197353 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 giveaway-skills-1776197353 技能

通过命令行安装

skillhub install giveaway-skills-1776197353

下载

⬇ 下载 giveaway-skills v0.1.0(免费)

文件大小: 4.5 KB | 发布时间: 2026-4-15 13:00

v0.1.0 最新 2026-4-15 13:00
Initial release of BSC Giveaway Contract Call Skill.

- Provides call guide and best practices for the Giveaway.sol contract on BSC mainnet.
- Documents core function signatures, parameters, method conventions, and contract address.
- Explains setup for creating and claiming giveaways, managing whitelists, and withdrawing expired giveaways.
- Includes usage examples for integrating with scripts and frontends using ethers.js.
- Offers concise overviews of distribution types, claim restrictions, and contract data structures.
- Lists minimal ABI information and guidance for both ERC20 and BNB giveaways.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部