Both,
struct Test {
uint x;
uint y;
}
contract A {
Test test;
}
and
contract A {
struct Test {
uint x;
uint y;
}
Test test;
}
are valid ways to define a struct. Is there any difference between both methods?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityBasically if you define struct outside the contract you are making it public and every contract which iport the .sol
file could use it where as if it is in the contract scope it is private and only the contract itself could use it. Also if it is outside you cold have problems with same named contract.
Example:
struct Test { ... }
contract Test { ... }