Contract "ItemMint" should be marked as abstract - ethereum

code
trying to create contract using KIP37 as base contract. its works fine for the previous version of #klaytn/contracts - 0.9.0, but it is not working for #klaytn/contracts - 1.0.0
//SPDX-License-Identifier: Unlincesed
pragma solidity ^0.8.0;
import "#klaytn/contracts/contracts/KIP/token/KIP37/KIP37.sol";
// this line showing error "Contract ItemMint should be abstract
contract ItemMint is KIP37 {
string public name;
constructor(string memory _name) {
name = _name;
}
function mint(address to) public pure returns (bool) {
require(msg.sender == to , "your are authorized");
return true;
}
}
using npm i #klaytn/contracts - 1.0.0

The parent KIP37 contract defines a constructor that takes one argument - a string named uri_, so you need to invoke the parent constructor as well.
constructor(string memory _name, string memory uri_) KIP37(uri_) {
name = _name;
}

Related

How to return a struct array in solidity with respect to web3j?

I've a smartcontract in which I've a function getLevels() that returns an array of struct type MLevel, defined at the beginning of smartcontract.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
struct MLevel{
address id;
string levelPrize;
uint levelNo;
uint levelCriteria;
}
contract Test{
MLevel[] public mlevels;
function addLevel(uint _levelCriteria, string memory _levelPrize)public payable{
MLevel memory level;
level.id = msg.sender;
level.levelCriteria = _levelCriteria;
level.levelPrize = _levelPrize;
mlevels.push(level);
}
function getLevels() public view returns(MLevel [] memory){
return mlevels;
}
}
The above smartcontract works absolutely fine in Remix ide. But when I try to create its java wrapper class using web3j, wrapper class does not generate and web3j ends with a weird error part 'struct MLevel' is keyword as shown below in the image

ChainID solidity version 0.6.12

I've seen this code working in many factory contracts:
constructor() public {
uint chainId;
assembly {
chainId := chainid
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);
}
However, this works when I use
pragma solidity =0.5.16;
But if I use pragma solidity =0.6.12;, I get an error:
ParseError: Expected '(' but got '}' } ^
I tried to do the following:
constructor() public {
uint chainId;
assembly {
chainId := chainid()
}...
But then I get multiple errors on variables and functions saying:
TypeError: overriding public state variable is missing string public constant name = ...
How do I write the assembly line in solidity version 0.6.12?
Thank you,
Using version 0.5.16 it's not an option because many imports use 0.6.12 and they won't work...
//SPDX-License-Identifier: MIT
pragma solidity =0.6.12;
contract Test {
string public constant name = "Your Contract name";
constructor() public {
uint chainId;
assembly {
chainId := chainid()
}
bytes32 DOMAIN_SEPARATOR;
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);}}
Try this. If you upgrade your code to version 0.8.0 and above there is a variable available in global namespace called
block.chainid

How to declare constants in Solidity

I am really new to Solidity and smart contracts and would really appreciate some help. I am following a tutorial and this is the exact code they use. But when I compile the code I get this error:
ParserError: Expected primary expression.
address public constant approver = ;
pragma solidity ^0.6.0;
contract ApprovalContract {
address public sender;
address public receiver;
address public constant approver = ;
function deposit(address _receiver) external payable {
require(msg.value > 0);
sender = msg.sender;
receiver = _receiver;
}
function viewApprover() external pure returns(address) {
return(approver);
}
function approve() external {
require(msg.sender == approver);
receiver.transfer(address(this).balance);
}
}
The constant needs to be initialized
address public constant approver = YOURADDRESS;
There are 2 types of constant variables in Solidity:
Constants: a variable that is hardcoded in the smart contract and that you cannot change the value
Immutables: variables you can only define the value in the constructor and that cannot be updated afterwards
Here is an example:
uint256 public constant EXAMPLE_NUMBER = 123;
unit256 public immutable EXAMPLE_NUMBER_2;
constructor(uint256 _number) {
EXAMPLE_NUMBER_2 = _number;
}
You can read more about it here.

Solidity public variable getter call doesn't return

I have deployed a very basic solidity contract (pragma solidity^0.4.0) to Rinkeby. When I call the getters on my state variables, nothing is returned and I do not understand why. To compile the contract I'm using "solc": "^0.4.25"
Using Remix to test, the call to the getter works locally without issue. However, the call doesn't work on my contract on Rinkeby.
Here is my solidity code...
pragma solidity^0.4.0;
contract Contest {
address public manager;
uint public submissionCost;
uint8 public votesPerSubmission;
constructor (uint _submissionCost, uint8 _votesPerSubmission) public {
manager = msg.sender;
submissionCost = _submissionCost;
votesPerSubmission = _votesPerSubmission;
}
modifier restricted() {
require(msg.sender == manager, "Not authorized.");
_;
}
function adjustSubmissionCost(uint32 newCost) public restricted {
submissionCost = newCost;
}
function adjustVotesPerSubmission(uint8 newVotes) public restricted {
votesPerSubmission = newVotes;
}
}
The address of the deployed contract on Rinkeby is
0xacBd19113e0D8122E18DF48A320b635fB5D7Cdd0
https://rinkeby.etherscan.io/address/0xacbd19113e0d8122e18df48a320b635fb5d7cdd0
When calling any of the public variables from Remix, I expect a return value, however I only receive the message call to Contest.manager in the Remix console and nothing more.
I get the same behavior in my web3 dapp, with zero return when I try...
await Contest.methods.manager().call()

solidity cannot access member variable from another contract on private chain, works fine on remix javascript vm

I have the following solidity code.
pragma solidity ^0.4.21;
contract Parent {
uint public childCount;
Child[] public children;
function makeChild(string name) external {
children.push(new Child(address(this), childCount, name));
childCount++;
}
function renameChild(uint index, string newName) external {
require(address(children[index]) != 0);
Child thisChild = Child(address(children[index]));
if (thisChild.isUpdated()) {
thisChild.rename(newName);
}
}
}
contract Child {
address parentAddress;
uint index;
string public name;
bool public isUpdated;
constructor(address parent, uint _index, string _name) public {
parentAddress = parent;
index = _index;
name = _name;
isUpdated = false;
}
function rename(string newName) external {
name = newName;
}
function renameViaParent(string updateName) external {
isUpdated = true;
Parent(parentAddress).renameChild(index, updateName);
}
}
I have been testing this code via Remix Solidity IDE. When I run in Javascript VM, I can create a child from parentInstance.makeChild("childName") and rename it using childInstance.renameViaParent("newName").
However when I switch to an Ethereum private chain, i.e. Injected Web3, I can still create the child, but fail in renaming using childInstance.renameViaParent("newName"). It gives the message:
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Invalid JSON RPC response: {"id":1830,"jsonrpc":"2.0","error":{"code":-32603}}
I tried to remove thisChild.isUpdated() condition check in renameChild(index, newName) and the code ran fine in both JS VM and private Web3. This is why I believe accessing the member variable isUpdated of Child from Parent is causing the problem.
What is wrong here? Probably with my private chain set up? How is it different from the Javascript VM Remix is using?
I am using geth-linux-amd64-1.8.6-12683 to run my private chain.