pragma solidity ^0.4.15;
import './ERC20.sol';
import './SafeMath.sol';
How connect SafeMath.sol from external(non-local) resourses?
pragma solidity ^0.4.15;
import './ERC20.sol';
import './SafeMath.sol';
How connect SafeMath.sol from external(non-local) resourses?
This is probably what you mean:
pragma solidity ^0.4.0;
import "github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol";
contract MathExtended {
using SafeMath for uint;
function exec(uint a, uint b) returns (uint){
return a.add(b);
}
}
Solidity supports importing from Github directly, just remember not to include commits or branches when reference it must be the user/project/file-path/file.sol directly.
See http://solidity.readthedocs.io/en/develop/layout-of-source-files.html
While James' answer is valid, I would not recommend linking your contract's dependencies from an online repository, this is highly insecure since your code depends on some online source that can be dynamically updated and because you might get unstable versions.
I would strongly recommend you follow Zeppelin's recommended way to use OpenZeppelin contracts, allowing you to use only stable releases and easily update the dependencies to get the latest features and bug-fixes:
npm init -y
npm install -E zeppelin-solidity
Then in your contract:
import 'zeppelin-solidity/contracts/math/SafeMath.sol';
contract MyContract {
using SafeMath for uint;
...
}
This is probably what you mean:
pragma solidity ^0.4.0;
import "github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol";
contract MathExtended {
using SafeMath for uint;
function exec(uint a, uint b) returns (uint){
return a.add(b);
}
}
Solidity supports importing from Github directly, just remember not to include commits or branches when reference it must be the user/project/file-path/file.sol directly.
See http://solidity.readthedocs.io/en/develop/layout-of-source-files.html
© 2022 - 2024 — McMap. All rights reserved.