pragma solidity ^0.6.0;
import "github.com/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol";
import "github.com/OpenZeppelin/openzeppelin-contracts/contracts/math/SafeMath.sol";
contract Fallback is Ownable {
using SafeMath for uint256;
mapping(address => uint) public contributions;
function Fallback() public {
contributions[msg.sender] = 1000 * (1 ether);
}
function contribute() public payable {
require(msg.value < 0.001 ether);
contributions[msg.sender] = contributions[msg.sender].add(msg.value);
if(contributions[msg.sender] > contributions[owner]) {
owner = msg.sender;
}
}
function getContribution() public view returns (uint) {
return contributions[msg.sender];
}
function withdraw() public onlyOwner {
owner.transfer(this.balance);
}
function fallback() payable public {
require(msg.value > 0 && contributions[msg.sender] > 0);
owner = msg.sender;
}
}
Hi! I just started with Ethernaut Series. The links on the contracts appeared to be broken on initial compilation so I fixed those. I also updated the solidity and compiler versions on Remix i.e 0.6.0. However, there’s still a compilation error. As follows
Uncaught JavaScript exception:
TypeError: soljson.Pointer_stringify is not a function
Anybody face a similar issue?
1 Like
Hi @sidheartx,
Great to hear that you have started playing Ethernaut.
There are a number of Ethernaut Community Solutions, and you would be very welcome to create your own too.
There are currently two version of Ethernaut. Solidity 0.4 and Solidity 0.5 (where the Solidity 0.4 version was upgraded to Solidity 0.5).
I assume you are using Solidity 0.5 version: https://solidity-05.ethernaut.openzeppelin.com/
The imports shown are if you are using tools such as OpenZeppelin CLI or Truffle.
To import in Remix via GitHub please see the Remix documentation:
https://remix-ide.readthedocs.io/en/latest/import.html#importing-from-github
We need to use the tag of an official OpenZeppelin Contracts release, which for Solidity 0.5 is 2.5.1.
For the Fallback level this looks like the following:
pragma solidity ^0.5.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/math/SafeMath.sol";
contract Fallback {
using SafeMath for uint256;
mapping(address => uint) public contributions;
address payable public owner;
constructor() public {
owner = msg.sender;
contributions[msg.sender] = 1000 * (1 ether);
}
modifier onlyOwner {
require(
msg.sender == owner,
"caller is not the owner"
);
_;
}
function contribute() public payable {
require(msg.value < 0.001 ether);
contributions[msg.sender] += msg.value;
if(contributions[msg.sender] > contributions[owner]) {
owner = msg.sender;
}
}
function getContribution() public view returns (uint) {
return contributions[msg.sender];
}
function withdraw() public onlyOwner {
owner.transfer(address(this).balance);
}
function() payable external {
require(msg.value > 0 && contributions[msg.sender] > 0);
owner = msg.sender;
}
}
Let me know if you have any questions.