I am doing a criptoCoin and I am using Solidity and I have the following code:
pragma solidity ^0.4.11;
interface IERC20 {
function totalSupply() constant returns (uint256 totalSupply);
function balanceOf(address _owner) constant returns (uint256 balance);
function transfer(address _to, uint256 _value) returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
function approve(address _spender, uint256 _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
For some reason it gives me this error:
browser/IERC20.sol:6:5: Warning: No visibility specified. Defaulting
to "public".
function transfer(address _to, uint256 _value) returns (bool success);
And it's giving this in all of my Functions, I don't know why.
Can anyone please tell me what's is going on ?
I am using Ethereum, Solidity and Metadata to do this, but to be able to do the next step I need my interface to work without any of these error.
I had to add the "Public" to the Function.
pragma solidity ^0.4.11;
interface IERC20 {
function totalSupply() public constant returns (uint256 totalSupply);
function balanceOf(address _owner) public constant returns (uint256 balance);
function transfer(address _to, uint256 _value) public returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
function approve(address _spender, uint256 _value) public returns (bool success);
function allowance(address _owner, address _spender) public constant returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
It is just a static warning you get when you don't describe the function as public explicitly but won't affect the working of contract.If you write a function definition for all it will run fine.
you have to add EXternal instead of public
function balanceOf(address _owner) external view returns (uint256 balance);
Related
I'd like to serialize a call using ethers, but only partially.
contract MockCall {
struct VoteResults {
uint256 votes;
bytes data;
}
event LogParam(uint256 param);
event LogParam(string name);
event LogParam(VoteResults[] results);
bool public isAction1 = false;
bool public isAction2 = false;
//I've only created this method so type chain would generate method stub
function Action(uint256 param1, string calldata name) public {
isAction1 = true;
}
// Intentionally leave 2 calldata parameters to verify appending calldata can work with trailing dynamic parameter
function Action(uint256 param1, string calldata name, VoteResults[] calldata voteResults) public {
isAction2 = true;
emit LogParam(param1);
emit LogParam(name);
emit LogParam(voteResults);
}
}
I would like to partially build the calldata, and my contract is going to handle injecting the rest of the parameters.
I've tried a few ways:
This way throws an error, in hexify, and sometimes json
let encodedFunctionCall = '';
try {
const rawInterface = new Interface("Action(uint256,string,(uint256,bytes)[]");
encodedFunctionCall = rawInterface.encodeFunctionData("Action(uint256,string,(uint256,bytes)[]", [BigNumber.from(5), "Abra"]);
}
catch(err) {
console.log(err);
}
This doesn't compile since it expects 3 parameters
const encodedFunctionCall = mockCall.interface.encodeFunctionData("Action(uint256,string,(uint256,bytes)[])", [BigNumber.from(5), "Abra"])
How do I partially construct calldata?
Here is the code for my main smart contract.
Errors on the last two functions.
from solidity: TypeError: Invalid type for argument in function call.
Invalid implicit conversion from type(uint256) to uint256 requested.
--> contracts/DIV4.sol:39:57: | 39 | randomness_interface(_random).fulfillRandomness(uint256); |
^^^^^^
from solidity: TypeError: Invalid type for argument in function call.
Invalid implicit conversion from type(bytes32) to bytes32 requested.
--> contracts/DIV4.sol:43:55: | 43 | randomness_interface(_random).getRandomNumber(bytes32); |
^^^^^^^
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";
import {randomness_interface} from "./randomness_interface.sol";
contract Divergence is ERC1155, Ownable {
uint256 public constant One = 0;
uint256 public constant Two = 1;
uint256 public constant Three = 2;
uint256 public constant Four = 3;
constructor() ERC1155 ("https://ipfs.io/ipfs/dsfgijdsfklj348rue0ur099045948.json"){
_mint(msg.sender, item1, 1000, "" );
_mint(msg.sender, item2, 130, "" );
_mint(msg.sender, item3, 65, "" );
_mint(msg.sender, item4, 3, "" );
}
function uri(uint256 _tokenId) override public view returns (string memory) {
return string(
abi.encodePacked(
"https://ipfs.io/ipfs/Qmf4WrTGA2fYJXitigvqJ7FDVMPreJQW4of8HZ1k5Wzkd3?filename=Divergence1",
Strings.toString(_tokenId),
".json"
)
);
}
function generateRandomNumber(address _random) external(bytes32 requestId) {
randomness_interface(_random).fulfillRandomness(uint256);
}
function getRandomNumberfromOutside(address _random) external {
randomness_interface(_random).getRandomNumber(bytes32);
}
Interface.sol file.
pragma solidity ^0.8.0;
interface randomness_interface {
function fulfillRandomness(uint256 randomness) external view returns (uint);
function getRandomNumber(bytes32 requestId) external;
}
Finally, the file with all the randomization happening.
pragma solidity ^0.6.6;
import "https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/VRFConsumerBase.sol";
contract RandomNumber is VRFConsumerBase {
bytes32 public keyHash;
uint256 public fee;
uint256 public randomResult;
constructor() VRFConsumerBase(0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, 0xa36085F69e2889c224210F603D836748e7dC0088) public {
keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4;
fee = 0.1 * 10 ** 18; //0.1 LINK
}
function getRandomNumber() public returns (bytes32 requestId) {
return requestRandomness(keyHash, fee);
}
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
randomResult = randomness.mod(100).add(1);
}
}
You are not passing correct arguments to the functions.
-
function generateRandomNumber(address _random) external(bytes32 requestId) {
randomness_interface(_random).fulfillRandomness(uint256);
}
You are calling randomness_interface(_random).fulfillRandomness and fulfillRandomness expects
function fulfillRandomness(bytes32 requestId, uint256 randomness)
I am not sure if this is the correct way of calling fulfillRandomness
function generateRandomNumber(address _random) external(bytes32 requestId) {
randomness_interface(_random).fulfillRandomness(uint256);
}
Because as far as I know, fulfillRandomness gets called by the chainlink node, so you make request, get the random number and then chainlink will call fulfillRandomness. I think you should have written like this:
function fulfillRandomness(bytes32 requestId,uint256 randomNumber) internal override{
}
In iterable.dart file, code for forEach is:
void forEach(void f(E element)) {
for (E element in this) f(element);
}
You can see, forEach parameter accepts a method and its return type should be void but following code just works fine without any error:
var list = [1, 2, 3];
list.forEach((item) {
print(item);
return true; // should show an error
});
The callback you pass to forEach() would be inferred as a bool Function(int), and List<int>.forEach() expects a void Function(int). This is accepted since T Function() is considered a subtype of void Function(); T Function() is substitutable anywhere void Function() is used.
I think in dart when you use the void return type with a function , the return type could be void or anything else
for example :
main()=>print(function() as int); // the output is 12
void function()=>12;
in this example the void function returns a value
example 2:
class Super {
void function(){}
}
class Child extends Super{
#override
int function(){
return 10;
}
you can override a function that have a type of void and change the type of the function to anything else.
I want to deploy my contract but I have so many warnings, I don't know every meaning.
Gas requirement of function SpastToken.increaseApproval(address,uint256) high. (11 times in other functions)
BasicToken.balanceOf(address) : Variables have very similar names balance and balances. Note: Modifiers are currently not considered by this static analysis.
Use assert(x) if you never ever want x to be false, not in any circumstance (apart from a bug in your code). Use require(x) if x can be false, due to e.g. invalid input or a failing external component.
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed
newOwner);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* #title ERC20 interface
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns
(uint256);
function transferFrom(address from, address to, uint256 value) public
returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256
value);
}
/**
* #title Basic token
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
}
/**
* #title Standard ERC20 token
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns
(uint256) {
return allowed[_owner][_spender];
}
function increaseApproval(address _spender, uint _addedValue) public returns
(bool) {
allowed[msg.sender][_spender] = allowed[msg.sender]
[_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public
returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract SpastToken is StandardToken, Ownable {
string public name;
string public symbol;
uint8 public decimals;
uint256 public initialSupply;
constructor() public {
name = 'SPAST-Coin';
symbol = 'SPAS';
decimals = 18;
initialSupply = 100000000 * 10 ** uint256(decimals);
totalSupply_ = initialSupply;
balances[owner] = initialSupply;
emit Transfer(0x0, owner, initialSupply);
}
}
I think these warnings are pretty self explanatory. Except maybe the last one about the assertion. That one basically says that you should use assert() to check for logic errors in your code(that would be something you did wrong), whereas you should use require() to check if the inputs are legal or not(that would be the callers mistake). I don't think the rest of the warnings can be explained further, consider googling them. The one with the variable names however is just there to help you avoid typos from similar variable names and will not affect execution in any way. The modifiers warnings that do not appear here try to tell you that you could have stricter modifiers for your functions which again would make reading the code simpler.
I'm trying to get a function import to work correctly. EF calls out to my stored procedure, but the result has an inner exception that I don't understand:
The 'IsPublished' property on 'uspLoadTemplateByID_Result' could not be set to a 'Int32' value. You must set this property to a
non-null value of type 'Boolean'.
My designer.cs are
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Boolean> IsPublished
{
get
{
return _IsPublished;
}
set
{
OnIsPublishedChanging(value);
ReportPropertyChanging("IsPublished");
_IsPublished = StructuralObject.SetValidValue(value);
ReportPropertyChanged("IsPublished");
OnIsPublishedChanged();
}
}
private Nullable<global::System.Boolean> _IsPublished;
partial void OnIsPublishedChanging(Nullable<global::System.Boolean> value);
partial void OnIsPublishedChanged();