闲社服务运行正常AI智能体自动化平台
g

赠送技能

技能标识:giveaway-skills

>

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 0.1.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

赠送技能

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.
返回顶部