1

I'm trying to create a smart contract to buy and sell documents. The truffle has the following token example.

pragma solidity ^0.4.4;

import 'zeppelin-solidity/contracts/token/StandardToken.sol';

contract TutorialToken is StandardToken {
    string public name = 'TutorialToken';
    string public symbol = 'TT';
    uint public decimals = 2;
    uint public INITIAL_SUPPLY = 12000;

    function TutorialToken() {
        totalSupply = INITIAL_SUPPLY;
        balances[msg.sender] = INITIAL_SUPPLY;
    }
}

Is it ok to add the following code to the same contract? Or is there a better way to do it? Is there a complete example? It sounds like a typical example.

contract TutorialToken is StandardToken {
    string public name = 'TutorialToken';
    string public symbol = 'TT';
    uint public decimals = 2;
    uint public INITIAL_SUPPLY = 12000;

    function TutorialToken() {
        totalSupply = INITIAL_SUPPLY;
        balances[msg.sender] = INITIAL_SUPPLY;
    }

    // Doc struct (maybe mapping (address => Doc))
    struct Doc {
        address seller;
        int docId;
        int priceByToken;
    }
    Doc[] Docs;

    function listDoc(int docId, int priceByToken) {
        // Insert into Docs (using sender's address)
    }

    mapping (address => Doc) Transactions;

    function buy(address buyer, address seller, int docId) {
        // Send token from buyer to seller and update Transactions
        transfer(seller, ..., buyer);
    }
}
  • This is a personal choice, I'd prefer to have the token functionality isolated from the buy/sell documents, but both solutions should work. – Ismael Dec 18 '17 at 5:52

Your Answer

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

Browse other questions tagged or ask your own question.