Solidity why the used function is placed before the brace when define a new function

0 votes

I saw a example for defining Token using  ERC721:

pragma solidity ^0.4.17;

import "./ERC721/ERC721Token.sol";

/**

* @title Repository of ERC721 Deeds

* This contract contains the list of deeds registered by users.

* This is a demo to show how tokens (deeds) can be minted and added

* to the repository.

*/

contract DeedRepository is ERC721Token {

/**

* @dev Created a DeedRepository with a name and symbol

* @param _name string represents the name of the repository

* @param _symbol string represents the symbol of the repository

*/

function DeedRepository(string _name, string _symbol)

public ERC721Token(_name, _symbol) {}

....

I have two questions:

1. Is the function DeedRepository a constructor? This method of defining a constructor with the same name as the contract has been obsoleted, hasn't it?

2. why "ERC721Token(_name, _symbol)" is before the brace "{}"? Here "ERC721Token" is a function that has been defined in ERC721Token. I think the function should be in the braces, like:

function DeedRepository(string _name, string _symbol) public{
ERC721Token(_name, _symbol)
}

shouldn't it?

Apr 3, 2019 in Blockchain by XHQ
1,266 views

1 answer to this question.

0 votes
Hey there!

1. Yes, using the same name for the constructor as that of the class name is obsoleted and the compiler would show an error if it was used. However, this happened since solidity version 0.4.22. So the older versions still allow constructor name to be same as the class name.

2. I think it is outside the braces because that is the syntax to use a class which is a direct implementation of the token. I am not sure about other reasons.
answered Apr 4, 2019 by Omkar
• 69,220 points

Thanks for your answer. It's really helpful. Will it work if i use the function ERC721Token inside the braces?

I don't think so. If you mention it inside the braces then it will a function called inside the DeedRepository function. But what we want is that the DeedRepository should be an implementation of the token.

May I know why do you want to put it inside the braces.

I now realize what you mean. I always thought ERC721Token is a function instead of a token itself. Thanks for your answer, It's really helpful.

Yes, that's what I meant. It was confusing to me also at first. I did some research and realized that its the implementation. Is there any particular reason you wanted to use that code inside the braces?
No, I don't have any particular reason to use that code inside the braces. I just thought it was the right way to put it in braces. Thanks again!

Related Questions In Blockchain

0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Why is it downloading the blocks when I am trying to deploy the ethereum private network?

Once you have installed the Ethereum wallet, ...READ MORE

answered May 3, 2018 in Blockchain by Shashank
• 10,400 points
654 views
+1 vote
3 answers

What is the pattern for handling throw on a Solidity contract in tests

In my opinion the cleanest way is: it("should ...READ MORE

answered Sep 25, 2018 in Blockchain by Lupin
1,806 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
1,411 views
0 votes
1 answer
0 votes
1 answer

TypeError: XMLHttpRequest is not a function when using web3 on meteor server side

I had the same problem. Instead ethereum:web3 Meteor package ...READ MORE

answered Oct 10, 2018 in Blockchain by Omkar
• 69,220 points
1,079 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP