I have two solidity files. Im trying to get access to one function that is in the second solidity file. I the first contract I import the file.

import "./DateTime.sol";

How can now acced to one function of the imported file???

DateTime dateTime = new DateTime();

My idea is to make what in Java it´s made like this.


Try this:

Let us assume the contract name of the first contract (the contract you imported) eg : contract1

Now use is keyword to implement the functions of that contract like this contract myContract2 is contract1 { // Your code }

Now use the the functions directly just like the example below:

pragma solidity ^0.4.22;

contract Factory {
    function getName() internal pure returns (string) {
        return "Your Name";

contract Contract is Factory {
    string public Name;

    constructor () public {
        Name = getName();

Hope this helps!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.