Importing provable in remix ide - solidity

I am trying to learn solidity on the online ide. I am trying to use Provable within the ide and I have activated the plugin. I thought maybe that could just inherit 'usingProvable' off the bat to my contract but the ide could not find the identifier. I tried importing the plugin from github but still is not able to find it. If anything it creates a bigger problem because the ide does not find any of the openzepplin files when I try to import the package. How would I accomplish this on the online ide?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "#openzeppelin/contracts#4.5.0/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts#4.5.0/token/ERC721/extensions/ERC721Enumerable.sol";
import "#openzeppelin/contracts#4.5.0/access/Ownable.sol";
import "#openzeppelin/contracts#4.5.0/utils/Counters.sol";
import "github.com/provable-things/ethereum-api/provableAPI.sol";
contract Neuron is ERC721, ERC721Enumerable, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("Neuron", "Neuron") {}
// function make_call() public {
// provable_query("URL","https://api.kraken.com/0/public/Ticker?pair=ETHXBT");
// }
function _baseURI() internal pure override returns (string memory) {
return "http://api.Neuron.com/tokens/";
}
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
this is a simple premade contract on remix and had not changed anything yet. I had commented out the function for testing a query call.

provable_api is a bit outdated. The file you import is a symlink to provableAPI_0.4.25.sol which allows compiler versions >= 0.4.22 < 0.5, while your imported OpenZeppelin contracts require ^0.8.0.
You can find a matching version
You can copy the provable_api contract locally in Remix IDE and use a relative path and try using a higher compiler version
PS. I think Remix IDE is having trouble with symbolic links. You can see the problem easier if you import the library like this:
import "github.com/provable-things/ethereum-api/provableAPI_0.5.sol";

Related

i am unable to use _totalSupply and _balances any private data type in OpenZeppelin and shows Undeclared identifier in solidity

Hey i am unable to implement _totalSupply and _balances in Remix but able to use remaining functions like name() and decimal() and symbol()
this is my code
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
contract METoken is ERC20 {
constructor(uint256 initialSupply) ERC20 ("MAstering ther","MET")
{
_totalSupply=initialSupply;
_balances[msg.sender] = initialSupply;
emit Transfer(address(0), msg.sender, initialSupply);
}
}
i am using ERC20 and i have seen from ERC20.sol file from Github that there are _totalSupply and other variables to use the totalSupply() method but i am not able to use them plz help!
In the OpenZeppelin ERC20 implementation, that you're importing to your contract, properties _totalSupply and _balances have the private visibility.
From the Solidity docs page:
Private state variables are like internal ones but they are not visible in derived contracts.
So these specific properties (with private visibility) are not visible in your contract that derives from the contract that declares them.
Solution: The parent contract defines the _mint() function that effectively increases the balance of a selected address, the total supply, as well as emits the Transfer event.
constructor(uint256 initialSupply) ERC20 ("MAstering ther","MET")
{
// increases `msg.sender`'s balance, total supply, and emits the `Transfer` event
_mint(msg.sender, initialSupply);
}

Read contract variable with only interface definition

I'm playing ethernaut Level 3, the original contract is here: https://ethernaut.openzeppelin.com/level/0x4dF32584890A0026e56f7535d0f2C6486753624f
When consecutiveWins is bigger or equal to 10, the player wins:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import '#openzeppelin/contracts/math/SafeMath.sol';
contract CoinFlip {
using SafeMath for uint256;
uint256 public consecutiveWins;
...
}
Now I want to read the consecutiveWins value in my contract, so I defined an interface:
interface CoinFlip {
uint256 public consecutiveWins;
function flip(bool _guess) external returns (bool);
}
But it is not allowed to have a variable in an interface, what should I do?
Solidity compiler will automatically generate getter functions for public variables, so what you need is replacing consecutiveWins variable in your interface with a getter function like this:
function consecutiveWins() public view returns (uint256);
You can read more about it in Solidity docs here.

Compiling an ERC721URIStorage contract

This question is essentially a follow-up to this question. I have been trying to follow Alchemy documentation to create an NFT contract but encountered the need (as described in the linked question) to import ERC721URIStorage. However, I now get a number of compilation problems that do not make clear sense to me.
In response to the first error (see below), I have tried adding in the import statement for ERC721: import "#openzeppelin/contracts/token/ERC721/ERC721.sol"; This did not change anything in the set of compilation errors.
It should be kinda like this :>
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/utils/Counters.sol";
contract LeafNFT is ERC721, ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("LeafNFT", "NFL") {}
function safeMint(address to, string memory uri) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}
I was able to get the code to work with a slight variation. The relevant points of confusion seem to be:
Whether zero, one, or two of {ERC721, ERC721URIStorage} should be imported. The answer appears to be to import only ERC721URIStorage.
Whether the contract is defined as ERC721URIStorage, ERC721, Ownable, or as ERC721URIStorage, Ownable. The answer appears to be the latter.
Whether the constructor uses ERC721 or ERC721URIStorage. The answer seems to be ERC721.
I think the first two of these points are intuitive (they are the first thing I tried and appear in the code shown in the question). This is because ERC721URIStorage inherits from ERC721, so there is no need to explicitly import ERC721 or define the contract as such.
The third point was less expected, but in hindsight, I think the constructor must cite ERC721 because ERC721URIStorage does not have a constructor of its own and because there is ambiguity about where a constructor can be inherited from (either from a parent of ERC721URIStorage or from Ownable).
Below is the working contract:

Lock transfer of erc721 NFT

Hi all I am building a blockchain-based game around an NFT project and am looking to understand if it's possible to implement the following.
Have a method on the NFT contract that when called can locks the transfer of all minted NFT's for a period. A bit like a game of tag than when your tag the contract all the (NFT / players) cant (move /transfer)
I assume I would need overide the transfer method then do a boolean check.
Something like
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
if(!isLocked){
safeTransferFrom(from, to, tokenId, "");
}
}
Will this work as I expect and is there any issues with this and would override the transfer method especially around security etc.
Sorry for such a broad question
Thanks
From the context, it seems like you're using the OpenZeppelin implementation. If that's the case, you can override their _beforeTokenTransfer() function, which is effectively called from all functions performing token transfer (as there is multiple of them).
pragma solidity ^0.8;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
contract MyCollection is ERC721 {
constructor() ERC721("MyCollection", "MyC") {
_mint(msg.sender, 1);
}
// needs to be unlocked for the `_mint()` function in constructor
bool locked = false;
function setLocked(bool _locked) external {
locked = _locked;
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override {
require(!locked, "Cannot transfer - currently locked");
}
}
If you're using other or custom implementation, or chose to only override the publicly visible functions, make sure that there is no other public or external function allowing the transfer without the lock mechanism.
Also few notes to your current code:
You probably won't need the virtual keyword. It allows the function to be further overridden. Unless you're expecting to override this function as well, you can safely remove the keyword.
You're calling the parent function with the same name but different argument set. If you wanted to call the parent function with the same name and the same argument set (assuming it's defined), you'd need to use the super keyword (same as in Java): super.safeTransferFrom(from, to, tokenId);

Erorr after truffle compile in Erc721 openzeppelin contract

im doing step by step of this article and i had a problem on truffle compile part.
I've got this error in cmd:
Error parsing #openzeppelin/contracts/token/ERC721/ERC721.sol: ParsedContract.sol:51:72: ParserError: Expected '{' but got reserved keyword 'override'
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
^------^
my contract :
pragma solidity ^0.6.0;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/utils/Counters.sol";
contract Uniken is ERC721{
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
mapping(string => uint8) hashes;
constructor() public ERC721("Uniken", "Ukn") {
}
function awardItem(address recipient, string memory hash, string memory metadata)
public
returns (uint256)
{
require(hashes[hash] != 1);
hashes[hash] = 1;
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, metadata);
return newItemId;
}
}
I'd be thankfull if anyone tell me whatis the problem?
It seems like it isn't seeing the ERC165 contract that ERC721 extends from. That function that it is getting stuck on should be overriding a function of the same name in ERC165, but the truffle compiler doesn't see a function named supportsInterface() in a class that ERC721 inherits from. So I would check to make sure everything imported in the ERC721 smart contract is in the right place in your folder structures, and that ERC721 is correctly inheriting ERC165.
After made some research , I was in truffle version 5.0 and update to the latest version of truffle -> v5.4.6, I am now able to compile