Solidity – How to Deploy an Owned Token Contract Through Remix

contract-developmentmetamaskremixsolidity

I have deployed a regular ERC20-compliant token contract through the Remix compiler and MetaMask. After doing so, the deployed token shows up on Etherscan as a token. However, when I try to deploy a token contract that is owned, it requires me to deploy the token contract and the owner contract separately, resulting in two isolated contracts that are from the same source code.

I use the very simple contract code from the official Ethereum website:
https://ethereum.org/token#full-coin-code

Any help you be appreciated

Best Answer

You don't need to deploy the inherited contract (owned) separately, you just need to inherit it in your token contract by adding in "is owned" (example below).

Some more information about inheritance here. http://solidity.readthedocs.io/en/develop/contracts.html#inheritance

pragma solidity ^0.4.18;

contract owned {
    function owned() { owner = msg.sender; }
    address owner;
}


// Use "is" to derive from another contract. Derived
// contracts can access all non-private members including
// internal functions and state variables. These cannot be
// accessed externally via `this`, though.
contract MyToken is owned {
    function kill() {
        if (msg.sender == owner) selfdestruct(owner);
    }
}

Then in Remix, you can choose to deploy MyToken only. Since the contract source code refers to owned ("is owned"), the owned code will be included in the compiled MyToken code.

Deploy MyToken only: Deploy MyToken only

Related Topic