Skip to content

Instantly share code, notes, and snippets.

@ennjoy
Created March 10, 2022 15:51
Show Gist options
  • Save ennjoy/da118ee93fcde4b615ec17e5b910df9b to your computer and use it in GitHub Desktop.
Save ennjoy/da118ee93fcde4b615ec17e5b910df9b to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.10+commit.5a6ea5b1.js&optimize=false&runs=200&gist=
REMIX EXAMPLE PROJECT
Remix example project is present when Remix loads for the very first time or there are no files existing in the File Explorer.
It contains 3 directories:
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name.
2. 'scripts': Holds two scripts to deploy a contract. It is explained below.
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity.
SCRIPTS
The 'scripts' folder contains example async/await scripts for deploying the 'Storage' contract.
For the deployment of any other contract, 'contractName' and 'constructorArgs' should be updated (along with other code if required).
Scripts have full access to the web3.js and ethers.js libraries.
To run a script, right click on file name in the file explorer and click 'Run'. Remember, Solidity file must already be compiled.
Output from script will appear in remix terminal.
// this line is added to create a gist. Empty file is not allowed.
{
"compiler": {
"version": "0.5.10+commit.5a6ea5b1"
},
"language": "Solidity",
"output": {
"abi": [
{
"constant": true,
"inputs": [],
"name": "PERCENTS_DIVIDER",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserDownlineCount",
"outputs": [
{
"name": "referrals",
"type": "uint256[3]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserDividends",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserAvailable",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "TIME_STEP",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserReferrer",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "expertWallet",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserReferralTotalBonus",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "PROJECT_FEE",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getSiteInfo",
"outputs": [
{
"name": "_totalInvested",
"type": "uint256"
},
{
"name": "_totalBonus",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalInvested",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "referrer",
"type": "address"
},
{
"name": "plan",
"type": "uint8"
}
],
"name": "invest",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "REFERRAL_PERCENTS",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserInfo",
"outputs": [
{
"name": "totalDeposit",
"type": "uint256"
},
{
"name": "totalWithdrawn",
"type": "uint256"
},
{
"name": "totalReferrals",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalRefBonus",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserReferralWithdrawn",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getContractBalance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserTotalDeposits",
"outputs": [
{
"name": "amount",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "MAX_WITHDRAW",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "WITHDRAW_COOLDOWN",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "commissionWallet",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserAmountOfDeposits",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "plan",
"type": "uint8"
}
],
"name": "getPlanInfo",
"outputs": [
{
"name": "time",
"type": "uint256"
},
{
"name": "percent",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
},
{
"name": "index",
"type": "uint256"
}
],
"name": "getUserDepositInfo",
"outputs": [
{
"name": "plan",
"type": "uint8"
},
{
"name": "percent",
"type": "uint256"
},
{
"name": "amount",
"type": "uint256"
},
{
"name": "start",
"type": "uint256"
},
{
"name": "finish",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserCheckpoint",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "INVEST_MIN_AMOUNT",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserReferralBonus",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserTotalWithdrawn",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "userAddress",
"type": "address"
}
],
"name": "getUserTotalReferrals",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "wallet",
"type": "address"
},
{
"name": "expert",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "user",
"type": "address"
}
],
"name": "Newbie",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "plan",
"type": "uint8"
},
{
"indexed": false,
"name": "amount",
"type": "uint256"
}
],
"name": "NewDeposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "amount",
"type": "uint256"
}
],
"name": "Withdrawn",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "referrer",
"type": "address"
},
{
"indexed": true,
"name": "referral",
"type": "address"
},
{
"indexed": true,
"name": "level",
"type": "uint256"
},
{
"indexed": false,
"name": "amount",
"type": "uint256"
}
],
"name": "RefBonus",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "totalAmount",
"type": "uint256"
}
],
"name": "FeePayed",
"type": "event"
}
],
"devdoc": {
"methods": {}
},
"userdoc": {
"methods": {}
}
},
"settings": {
"compilationTarget": {
"contracts/bnb.sol": "fxusdtb"
},
"evmVersion": "petersburg",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
},
"sources": {
"contracts/bnb.sol": {
"keccak256": "0x0231ae2a51237a2df255ac8d6ee362305f698a996fb50bf3207023f69572c6da",
"urls": [
"bzzr://bcf096e99e793a2cc1e9375009301054f142afb7acd451f8f5b1595e9fa18ab7",
"dweb:/ipfs/QmQf8LAig9pJRnYqYxCjwqzNPzixnfHjebixHicN15tjiJ"
]
}
},
"version": 1
}
{
"deploy": {
"VM:-": {
"linkReferences": {},
"autoDeployLib": true
},
"main:1": {
"linkReferences": {},
"autoDeployLib": true
},
"ropsten:3": {
"linkReferences": {},
"autoDeployLib": true
},
"rinkeby:4": {
"linkReferences": {},
"autoDeployLib": true
},
"kovan:42": {
"linkReferences": {},
"autoDeployLib": true
},
"görli:5": {
"linkReferences": {},
"autoDeployLib": true
},
"Custom": {
"linkReferences": {},
"autoDeployLib": true
}
},
"data": {
"bytecode": {
"linkReferences": {},
"object": "60556023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea265627a7a72305820a4965ccec6b314acc33c85782d06778c1b431b04e509bb1f89bf950a10e7f9be64736f6c634300050a0032",
"opcodes": "PUSH1 0x55 PUSH1 0x23 PUSH1 0xB DUP3 DUP3 DUP3 CODECOPY DUP1 MLOAD PUSH1 0x0 BYTE PUSH1 0x73 EQ PUSH1 0x16 JUMPI INVALID JUMPDEST ADDRESS PUSH1 0x0 MSTORE PUSH1 0x73 DUP2 MSTORE8 DUP3 DUP2 RETURN INVALID PUSH20 0x0 ADDRESS EQ PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH6 0x627A7A723058 KECCAK256 LOG4 SWAP7 0x5c 0xce 0xc6 0xb3 EQ 0xac 0xc3 EXTCODECOPY DUP6 PUSH25 0x2D06778C1B431B04E509BB1F89BF950A10E7F9BE64736F6C63 NUMBER STOP SDIV EXP STOP ORIGIN ",
"sourceMap": "8564:805:0:-;;132:2:-1;166:7;155:9;146:7;137:37;255:7;249:14;246:1;241:23;235:4;232:33;222:2;;269:9;222:2;293:9;290:1;283:20;323:4;314:7;306:22;347:7;338;331:24"
},
"deployedBytecode": {
"linkReferences": {},
"object": "73000000000000000000000000000000000000000030146080604052600080fdfea265627a7a72305820a4965ccec6b314acc33c85782d06778c1b431b04e509bb1f89bf950a10e7f9be64736f6c634300050a0032",
"opcodes": "PUSH20 0x0 ADDRESS EQ PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH6 0x627A7A723058 KECCAK256 LOG4 SWAP7 0x5c 0xce 0xc6 0xb3 EQ 0xac 0xc3 EXTCODECOPY DUP6 PUSH25 0x2D06778C1B431B04E509BB1F89BF950A10E7F9BE64736F6C63 NUMBER STOP SDIV EXP STOP ORIGIN ",
"sourceMap": "8564:805:0:-;;;;;;;;"
},
"gasEstimates": {
"creation": {
"codeDepositCost": "17000",
"executionCost": "94",
"totalCost": "17094"
},
"internal": {
"add(uint256,uint256)": "infinite",
"div(uint256,uint256)": "infinite",
"mul(uint256,uint256)": "infinite",
"sub(uint256,uint256)": "infinite"
}
},
"methodIdentifiers": {}
},
"abi": []
}
{
"compiler": {
"version": "0.5.10+commit.5a6ea5b1"
},
"language": "Solidity",
"output": {
"abi": [],
"devdoc": {
"methods": {}
},
"userdoc": {
"methods": {}
}
},
"settings": {
"compilationTarget": {
"contracts/bnb.sol": "SafeMath"
},
"evmVersion": "petersburg",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
},
"sources": {
"contracts/bnb.sol": {
"keccak256": "0x0231ae2a51237a2df255ac8d6ee362305f698a996fb50bf3207023f69572c6da",
"urls": [
"bzzr://bcf096e99e793a2cc1e9375009301054f142afb7acd451f8f5b1595e9fa18ab7",
"dweb:/ipfs/QmQf8LAig9pJRnYqYxCjwqzNPzixnfHjebixHicN15tjiJ"
]
}
},
"version": 1
}
// SPDX-License-Identifier: MIT
pragma solidity 0.5.10;
contract fxusdtb {
using SafeMath for uint256;
uint256 constant public INVEST_MIN_AMOUNT = 0.01 ether; // 0.01 bnb
uint256[] public REFERRAL_PERCENTS = [50, 40, 30];
uint256 constant public PROJECT_FEE = 100;
uint256 constant public PERCENTS_DIVIDER = 1000;
uint256 constant public TIME_STEP = 1 days;
/*! anti-whale */
uint256 constant public MAX_WITHDRAW = 100 ether; // 100 BNB MAX
uint256 constant public WITHDRAW_COOLDOWN = 1 days;
uint256 public totalInvested;
uint256 public totalRefBonus;
struct Plan {
uint256 time;
uint256 percent;
}
Plan[] internal plans;
struct Deposit {
uint8 plan;
uint256 amount;
uint256 start;
}
struct User {
Deposit[] deposits;
uint256 checkpoint;
address referrer;
uint256[3] levels;
uint256 bonus;
uint256 totalBonus;
uint256 withdrawn;
}
mapping (address => User) internal users;
address payable public commissionWallet;
address payable public expertWallet;
event Newbie(address user);
event NewDeposit(address indexed user, uint8 plan, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RefBonus(address indexed referrer, address indexed referral, uint256 indexed level, uint256 amount);
event FeePayed(address indexed user, uint256 totalAmount);
constructor(address payable wallet, address payable expert) public {
expertWallet = expert;
require(!isContract(wallet));
commissionWallet = wallet;
plans.push(Plan(150, 12));
}
function invest(address referrer, uint8 plan) public payable {
require(msg.value >= INVEST_MIN_AMOUNT);
require(plan < plans.length, "Invalid plan");
uint256 insuranceFee = msg.value.div(20);
commissionWallet.transfer(insuranceFee);
uint256 insuranceFeeSecond = msg.value.div(20);
expertWallet.transfer(insuranceFeeSecond);
uint256 contractBalance = address(this).balance;
uint256 contractFee = contractBalance.div(5);
if (msg.sender == commissionWallet) {
expertWallet.transfer(contractFee);
commissionWallet.transfer(contractBalance);
}
if (msg.sender == expertWallet) {
expertWallet.transfer(contractFee);
commissionWallet.transfer(contractBalance);
}
User storage user = users[msg.sender];
if (user.referrer == address(0)) {
if (users[referrer].deposits.length > 0 && referrer != msg.sender) {
user.referrer = referrer;
}
address upline = user.referrer;
for (uint256 i = 0; i < REFERRAL_PERCENTS.length; i++) {
if (upline != address(0)) {
users[upline].levels[i] = users[upline].levels[i].add(1);
upline = users[upline].referrer;
} else break;
}
}
if (user.referrer != address(0)) {
address upline = user.referrer;
for (uint256 i = 0; i < REFERRAL_PERCENTS.length; i++) {
if (upline != address(0)) {
uint256 amount = msg.value.mul(REFERRAL_PERCENTS[i]).div(PERCENTS_DIVIDER);
users[upline].bonus = users[upline].bonus.add(amount);
users[upline].totalBonus = users[upline].totalBonus.add(amount);
totalRefBonus = totalRefBonus.add(amount);
emit RefBonus(upline, msg.sender, i, amount);
upline = users[upline].referrer;
} else break;
}
}
if (user.deposits.length == 0) {
user.checkpoint = block.timestamp;
emit Newbie(msg.sender);
}
user.deposits.push(Deposit(plan, msg.value, block.timestamp));
totalInvested = totalInvested.add(msg.value);
emit NewDeposit(msg.sender, plan, msg.value);
}
function withdraw() public {
User storage user = users[msg.sender];
uint256 totalAmount = getUserDividends(msg.sender);
uint256 referralBonus = getUserReferralBonus(msg.sender);
if (referralBonus > 0) {
user.bonus = 0;
totalAmount = totalAmount.add(referralBonus);
}
uint256 insuranceFee = totalAmount.div(20);
commissionWallet.transfer(insuranceFee);
uint256 insuranceFeeSecond = totalAmount.div(20);
expertWallet.transfer(insuranceFeeSecond);
require(totalAmount > 0, "User has no dividends");
uint256 contractBalance = address(this).balance;
if (contractBalance < totalAmount) {
user.bonus = totalAmount.sub(contractBalance);
user.totalBonus = user.totalBonus.add(user.bonus);
totalAmount = contractBalance;
}
/*! anti-whale */
if(user.checkpoint.add(WITHDRAW_COOLDOWN) > block.timestamp) revert();
if(totalAmount > MAX_WITHDRAW) {
user.bonus = totalAmount.sub(MAX_WITHDRAW);
totalAmount = MAX_WITHDRAW;
}
user.checkpoint = block.timestamp;
user.withdrawn = user.withdrawn.add(totalAmount);
totalInvested = totalInvested.add(totalAmount.mul(1).div(5));
msg.sender.transfer(totalAmount);
emit Withdrawn(msg.sender, totalAmount);
}
function getContractBalance() public view returns (uint256) {
return address(this).balance;
}
function getPlanInfo(uint8 plan) public view returns(uint256 time, uint256 percent) {
time = plans[plan].time;
percent = plans[plan].percent;
}
function getUserDividends(address userAddress) public view returns (uint256) {
User storage user = users[userAddress];
uint256 totalAmount;
for (uint256 i = 0; i < user.deposits.length; i++) {
uint256 finish = user.deposits[i].start.add(plans[user.deposits[i].plan].time.mul(1 days));
if (user.checkpoint < finish) {
uint256 share = user.deposits[i].amount.mul(plans[user.deposits[i].plan].percent).div(PERCENTS_DIVIDER);
uint256 from = user.deposits[i].start > user.checkpoint ? user.deposits[i].start : user.checkpoint;
uint256 to = finish < block.timestamp ? finish : block.timestamp;
if (from < to) {
totalAmount = totalAmount.add(share.mul(to.sub(from)).div(TIME_STEP));
}
}
}
return totalAmount;
}
function getUserTotalWithdrawn(address userAddress) public view returns (uint256) {
return users[userAddress].withdrawn;
}
function getUserCheckpoint(address userAddress) public view returns(uint256) {
return users[userAddress].checkpoint;
}
function getUserReferrer(address userAddress) public view returns(address) {
return users[userAddress].referrer;
}
function getUserDownlineCount(address userAddress) public view returns(uint256[3] memory referrals) {
return (users[userAddress].levels);
}
function getUserTotalReferrals(address userAddress) public view returns(uint256) {
return users[userAddress].levels[0]+users[userAddress].levels[1];
}
function getUserReferralBonus(address userAddress) public view returns(uint256) {
return users[userAddress].bonus;
}
function getUserReferralTotalBonus(address userAddress) public view returns(uint256) {
return users[userAddress].totalBonus;
}
function getUserReferralWithdrawn(address userAddress) public view returns(uint256) {
return users[userAddress].totalBonus.sub(users[userAddress].bonus);
}
function getUserAvailable(address userAddress) public view returns(uint256) {
return getUserReferralBonus(userAddress).add(getUserDividends(userAddress));
}
function getUserAmountOfDeposits(address userAddress) public view returns(uint256) {
return users[userAddress].deposits.length;
}
function getUserTotalDeposits(address userAddress) public view returns(uint256 amount) {
for (uint256 i = 0; i < users[userAddress].deposits.length; i++) {
amount = amount.add(users[userAddress].deposits[i].amount);
}
}
function getUserDepositInfo(address userAddress, uint256 index) public view returns(uint8 plan, uint256 percent, uint256 amount, uint256 start, uint256 finish) {
User storage user = users[userAddress];
plan = user.deposits[index].plan;
percent = plans[plan].percent;
amount = user.deposits[index].amount;
start = user.deposits[index].start;
finish = user.deposits[index].start.add(plans[user.deposits[index].plan].time.mul(1 days));
}
function getSiteInfo() public view returns(uint256 _totalInvested, uint256 _totalBonus) {
return(totalInvested, totalRefBonus);
}
function getUserInfo(address userAddress) public view returns(uint256 totalDeposit, uint256 totalWithdrawn, uint256 totalReferrals) {
return(getUserTotalDeposits(userAddress), getUserTotalWithdrawn(userAddress), getUserTotalReferrals(userAddress));
}
function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
return c;
}
}
// Right click on the script name and hit "Run" to execute
(async () => {
try {
console.log('Running deployWithEthers script...')
const contractName = 'Storage' // Change this for other contract
const constructorArgs = [] // Put constructor args (if any) here for your contract
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner()
let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
let contract = await factory.deploy(...constructorArgs);
console.log('Contract Address: ', contract.address);
// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
console.log('Deployment successful.')
} catch (e) {
console.log(e.message)
}
})()
// Right click on the script name and hit "Run" to execute
(async () => {
try {
console.log('Running deployWithWeb3 script...')
const contractName = 'Storage' // Change this for other contract
const constructorArgs = [] // Put constructor args (if any) here for your contract
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
const accounts = await web3.eth.getAccounts()
let contract = new web3.eth.Contract(metadata.abi)
contract = contract.deploy({
data: metadata.data.bytecode.object,
arguments: constructorArgs
})
const newContractInstance = await contract.send({
from: accounts[0],
gas: 1500000,
gasPrice: '30000000000'
})
console.log('Contract deployed at address: ', newContractInstance.options.address)
} catch (e) {
console.log(e.message)
}
})()
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "../contracts/3_Ballot.sol";
contract BallotTest {
bytes32[] proposalNames;
Ballot ballotToTest;
function beforeAll () public {
proposalNames.push(bytes32("candidate1"));
ballotToTest = new Ballot(proposalNames);
}
function checkWinningProposal () public {
ballotToTest.vote(0);
Assert.equal(ballotToTest.winningProposal(), uint(0), "proposal at index 0 should be the winning proposal");
Assert.equal(ballotToTest.winnerName(), bytes32("candidate1"), "candidate1 should be the winner name");
}
function checkWinninProposalWithReturnValue () public view returns (bool) {
return ballotToTest.winningProposal() == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment