Skip to content

合约方法模块

合约方法模块汇总了前端与后端常用的链上调用入口,包含方法签名、参数说明以及返回数据结构,便于在集成钱包或后台任务时快速查阅。

方法清单

deposit

签名: function deposit(uint256 roundId, address referrer) payable 说明: 向指定轮次存入 ETH,允许携带推荐人地址。调用方需确保 msg.value 等于本次参与的金额。

请求字段

NameRequiredTypeDescription
round_idYesnumber开放状态的轮次 ID。
referrerNostring推荐人地址;如果为空地址则不记录推荐关系。

返回字段

无返回值,成功会触发 MultipleRoundsDepositedDeposited 等事件以便追踪结果。


batchDeposit

签名: function batchDeposit(uint256 startingRoundId, uint256[] amounts, address referrer) payable 说明: 一次性向连续轮次批量存入 ETH,适合预购多个回合。msg.value 需要等于 amounts 数组之和。

请求字段

NameRequiredTypeDescription
starting_round_idYesnumber第一笔存入的轮次 ID,必须是开放状态。
amountsYesnumber[]每个轮次的存入金额(wei);数组长度等于参与轮次数。
referrerNostring推荐人地址;为空地址时不记录推荐关系。

返回字段

方法无直接返回值;结果可通过 MultipleRoundsDepositedRollover 等事件确认。


drawWinner

签名: function drawWinner() 说明: 触发当前可开奖轮次的开奖流程,内部会请求随机数并在完成后结算。

请求字段

NameRequiredTypeDescription
---无需传入参数。

返回字段

无直接返回值;开奖流程完成后会触发 RandomnessRequestedPrizeAwarded 等事件。


withdraw

签名: function withdraw() 说明: 提取调用者在合约中的可取余额,通常来自退款或中奖奖励。

请求字段

NameRequiredTypeDescription
---无需传入参数。

返回字段

无直接返回值;余额提取成功后会触发 PrizeAwardedReferrerRewarded 等事件以供追踪。


getWithdrawableBalance

签名: function getWithdrawableBalance(address depositor) external view returns (uint256) 说明: 查询指定地址当前可提现的余额(wei),常用于展示用户可提额度或在调用 withdraw 前进行校验。

请求字段

NameRequiredTypeDescription
depositorYesstring需查询的用户地址。

返回字段

NameRequiredTypeDescription
withdrawable_balanceYesstring可立即提取的余额(wei)。

rollover

签名: function rollover(uint256 roundId, uint256 rolloverAmount) 说明: 将调用者在合约中的余额滚入指定轮次,便于继续参与下一轮。

请求字段

NameRequiredTypeDescription
round_idYesnumber目标轮次 ID。
rollover_amountYesstring要滚入的金额(wei)。

返回字段

无直接返回值;滚入成功后会通过 RolloverRoundStatusUpdated 等事件反映状态。


getRound

签名: function getRound(uint256 roundId) view returns (RoundStatus status, uint40 maximumNumberOfParticipants, uint16 roundProtocolFeeBp, uint40 cutoffTime, uint40 drawnAt, uint40 numberOfParticipants, address winner, uint96 roundValuePerEntry, Deposit[] deposits) 说明: 查询指定轮次的详细状态与参与记录,可在服务端缓存供前端读取。

请求字段

NameRequiredTypeDescription
round_idYesnumber要查询的轮次 ID。

返回字段

NameRequiredTypeDescription
statusYesRoundStatus轮次当前状态。
maximum_number_of_participantsYesnumber轮次允许的最大参与人数。
round_protocol_fee_bpYesnumber轮次使用的协议费基点。
cutoff_timeYesnumber存款截止时间戳(秒)。
drawn_atNonumber开奖完成时间戳(秒),若尚未开奖则为 0。
number_of_participantsYesnumber当前参与人数。
winnerNostring获胜者地址,开奖前为零地址。
round_value_per_entryYesstring每次参与的金额(wei)。
depositsYesDeposit[]轮次的存款明细数组。

相关类型

RoundStatus 枚举

NameTypeDescription
nonestring轮次不存在。
openstring正在开放,允许新的存款。
drawingstring开奖中,等待随机数完成。
drawnstring已开奖并记录结果。
cancelledstring被取消,后续等待退款。

Deposit 对象

NameTypeDescription
amountstring存款金额(wei)。
depositorstring存款人地址。
current_entry_indexnumber存款对应的参与索引,用于计算抽奖份额。

集成建议

  • payable 的方法必须通过钱包或后端签名交易,并设置合适的 gas 限制。
  • nonReentrantwhenNotPaused 修饰器意味着方法在合约暂停或重入保护触发时会 revert,调用前应拉取最新 OutflowAllowedUpdatedRoundStatusUpdated 等事件做前置校验。
  • 推荐在服务端缓存 getRound 返回结果,并通过事件监听实现增量更新,降低链上请求次数。