Created
March 1, 2020 11:45
-
-
Save perfectmak/f2801112df47e81d1b65f8dd1546c3a9 to your computer and use it in GitHub Desktop.
A solidity Loan smart contract built at the blockchain meetup in Lagos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.6.1; | |
interface MoneyToken { | |
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success); | |
} | |
contract Loan { | |
mapping(address => int256) public loanRegistry; | |
address owner = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
/** | |
* Note: this ngnt address is the mainnet address | |
* So it would only target the actual account if on mainnet. | |
* NGNT is an ERC20 standard token so you can deploy a similar token | |
* on this network. See here for the specs: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md | |
*/ | |
address ngntTokenAddress = 0x05BBeD16620B352A7F889E23E3Cf427D1D379FFE; | |
function sendLoan(int256 amount, address recipientsAddress) external { | |
// ensure we are not loaning negative value | |
require(amount > 0, "Loaning negative value wrong"); | |
require(msg.sender == owner, "You are not owner"); | |
// if we have loaned recipient previously update the loanRegistry | |
int256 currentValue = loanRegistry[recipientsAddress]; | |
loanRegistry[recipientsAddress] = currentValue + amount; | |
// transfer actual money token | |
MoneyToken ngntToken = MoneyToken(ngntTokenAddress); | |
require(ngntToken.transferFrom(owner, recipientsAddress, uint256(amount)), "Failed to transfer loan to receipient"); | |
} | |
} |
A updated more dynamic version of this can be found here: https://gist.github.com/perfectmak/d32bad707d0b0c2caee6f257f2368f70
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you were sending ethereum as the token, then you don't need the
MoneyToken
(aka part-ERC20) interface, what you would need to is: