## React + thirdweb 前端串接智能合約範例 ```solidity // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.9; contract Lottery { address payable[] public players; address public lastWinner; address public manager; constructor() { manager = msg.sender; } function enter() public payable { require(msg.value == 0.01 ether); players.push(payable(msg.sender)); } function getBalance() public view returns (uint256) { return address(this).balance; } function getPlayers() public view returns (address payable[] memory) { return players; } function random() public view returns (uint256) { return uint256( keccak256( abi.encodePacked( block.difficulty, block.timestamp, players.length ) ) ); } function pickWinner() public { require(msg.sender == manager); uint256 r = random(); address payable winner; uint256 index = r % players.length; winner = players[index]; lastWinner = winner; winner.transfer(getBalance()); players = new address payable[](0); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up