2

I would like to create two types of tokens:

  1. Let's call them ND, about 10 contracts with non-divisible tokens (so far) in the mapping uint => address
  2. Let's call it DV, one contract with divisible ether-like tokens

In my contract users can buy DV for ether, it's working. But the problem is that I want to make an automatic way to buy ND with DV, for example with function.

For example I set price 0.1 of ND[3] (3rd from the array of 10 total), and when user want to buy ND[3] and send 0.1 of DV, will recive 1 ND[3].

I would need to implement cross trade between contracts somehow. Does anybody have any kind of help how can I make such thing?

For now two tokens are pretty basic from tutorial with simple buy for ether function and decimals difference, as said above, so I don't think there is any need to share that extremely basic code.

1 Answer 1

1

As token contract itself usually doesn't include any purchasing mechanisms you can probably have quite standard token contracts. Especially if transferring DV tokens in normal way is ok - if it's not then you need to disallow transfers where the transferrer (msg.sender) is not ND.

To allow purchasing/trading of DV tokens from ND, you need an extra purchase/trade function. This function should only allow calls from the ND contract, so something like this:

address ndAddress;

    modifier onlyND() {
        require(msg.sender == ndAddress);
        _;
    }

    function purchase() onlyND public {
        // purchase process
    }

As you create both tokens you can just add whatever purchase logic you wish - decrease/increase balances as needed. Remember that you need special implementation in both token contracts to modify its internal token balances - you can't modify another token's internal balances directly from a different token contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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