Interactions between contracts?Contract inheritance? Need some help to understand certain things

Viktor1986Viktor1986 Posts: 1Member
I'm using testrpc, and truffle. I created a simple token as seen in many tutorials which shall be used to buy or enable certain actions when clicking a button on an UI.
    contract MyToken {
mapping (address => uint) balanceOf;

event CoinTransfer(address indexed _from, address indexed _to, uint256 _value);

function MyToken() {
balanceOf[msg.sender] = 21000000;
}

function sendCoin(address receiver, uint amount) returns(bool sufficient) {
if (balanceOf[msg.sender] < amount) return false;
balanceOf[msg.sender] -= amount;
balanceOf[receiver] += amount;
CoinTransfer(msg.sender, receiver, amount);
return true;
}

function getBalance(address addr) returns(uint) {
return balanceOf[addr];
}
}
So far so good.

The UI has a button "buy 10 MyToken" which is working as I have implemented a function in app.js with the deployed JS object of that contract.
    function buyMyToken(amount) {
var mytoken = MyToken.deployed();

showStatus("Initiating transaction... (please wait)");

mytoken.sendCoin(myaccount, amount, {from: spender}).then(function() {
showStatus("Transaction complete!");
refreshBalance();
}).catch(function(e) {
console.log(e);
showStatus("Error sending coin; see log.", true);
});
};
Now I want to create another contract which will allow the user to buy a licence,service or enable some action for instance,when clicking another button.Which in that case shall enable a picture permanently on the UI when being bought once with that token.
So that second button should enable a gimmick permanently and the cost is for instance 5 of my own created token --> "enable gimmick (5 MyToken)"

For that contract inheritance is needed right?
Because the second contract has to check if the user has already bought some of the tokens with the first contract, which would allow him to buy some license,service or enable some action with the second contract.
So what do I need for that second contract and how can I build and use it in connection with the first contract?

Could second contract be like this or what else do I need?I know I need for instance the getBalance function from the first contract right?But how and where I put it?
  contract PermService {
address vendor;

event ServiceTransfer(address _from, address _to, uint _amount)

function PermService() {
vendor = msg.sender;


}

function buyPermService() returns (bool success) {
if...
...
ServiceTransfer(msg.sender, receiver, amount);
return true;
}
}
Does that even make any sense?

Can not really find good tutorials for subcurrencies and how to use them with other contracts. I'm also a noob and not a pro coder.

And can I do simulate that with truffle console?

Help is much appreciated. Thanks in adavance.
Sign In or Register to comment.