0

[Edit 14-03-2018] I want to create a contract A that can generate a random number of Token A and another contract B that receive and destroy one or many of this token to generate a new Token B.

It's like sending one CryptosKitty to another contract B, burn the kitty, and generate a Dog with the kitty's gen.

Thanks for the help.

3
  • You will have to provide more context.
    – ivicaa
    Commented Mar 9, 2018 at 19:15
  • it is not possible to generate trully random numbers in a contract. The last guy who tried it, lost his 2k Ethers, that was about a year ago.
    – Nulik
    Commented Mar 11, 2018 at 21:33
  • your token must know the address of the destroyer contract and when it receives a particular message it could set the token balance to zero.
    – Nulik
    Commented Mar 11, 2018 at 21:35

2 Answers 2

1

In case contract A allows token holders to burn their tokens, you just need to call corresponding method of contract A from contract B like this:

contract B is ERC721 {
  uint nextDogID = 0;
  A a = ...;

  function catToDog (uint _catID) public (returns _dogID) {
    _dogID = nextDogID++;
    _mint (msg.sender, _dogID);
    copyGene (_catID, _dogID);
    require (a.transferFrom (msg.sender, address (this), _catID));
    require (a.burn (_catID)); // Here we burn the cat token!
  }
}

If A does not allow burning, just send "burned" tokens to some dead address:

contract B is ERC721 {
  uint nextDogID = 0;
  IERC721 a = ...;

  function catToDog (uint _catID) public (returns _dogID) {
    _dogID = nextDogID++;
    _mint (msg.sender, _dogID);
    copyGene (_catID, _dogID);

    // Here we send the cat token to dead address effectively burning it
    require (a.transferFrom (
      msg.sender,
      0x000000000000000000000000000000000000dead,
      _catID));
  }
}
0

You don't actually need to "receive" anything. The contract B just needs to be able to burn some tokens which are listed in contract A.

Here's some example code:

contract A {
    uint tokens = 10;
    // which address is allowed to burn tokens
    address allowedBurnerAddress = 0x1234;

    // allowed contract (B) can call this to burn tokens
    function burn(uint amount) public {
        require(msg.sender == allowedBurnerAddress);
        tokens -= amount;
    }
}

contract B {
    // address for contract A
    address burnContract = 0x0987;

    // call this to burn tokens which exist in contract A
    function PerformBurn() public {
        // add some requirements for who can call this function

        A original = A(burnContract);
        original.burn(5);
    }
}

Your Answer

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

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