If I make an ethereum smart contract - call it simplecoin, can I set it up such that I can allow users of the coin to mine the transactions? Rather than a generic ethereum miner that would charge gas?
Is this possible?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityYes it is possible. However, it depends how you define "mining".
Normally mining means the action of a consensus protocol, like Proof of Work, or Proof of Stake, etc. So it will affect how coins are created. You will need to be very careful to allow the execution of
coins[msg.sender] += 5;
which means the creation must be in the guidance of the consensus protocol.
Here is an example. You define an new coin (ERC20)
with following feature:
Every 100 block, you give 5% interests to token holder.
func getInterest(){
if( (coins[msg.sender].lastClainBlk + 100 ) < block.number ){
coins[msg.sender].balance += coins[msg.sender].balance *RATE;
coins[msg.sender].lastClainBlk = block.number
}
}
Token holder can explicitly call this function to claim the interest. Or done implicitly during transfer.
Yes, this is possible.
Just create a function in your contract that takes an array of transactions and a nonce:
assert(transactionsValid(transactions));
var new_head = hash(transactions, nonce, blockhead);
assert(new_head < threshold);
coins[msg.sender] += 5;
blockhead = new_head;
Most likely you'd ommit transactions and just keep nonce and head.
No: I'm assuming your smart contract requires modifying the blockchain (you mention "coin", so presumably you track balances on-chain).
You can have an Ethereum smart contract that validates transactions using a mining process. However, it can only be in addition to, not instead of the regular Ethereum mining process. If a contract modifies the blockchain, it will consume gas which must be paid for using ether. A corollary is that your minimum (on-chain) confirmation time is Ethereum's block time. More generally, you cannot write an Ethereum smart-contract to get around the rules of Ethereum.
As far as I know, this is not a possibility. At this point, all transactions are processed by running nodes (miners).
What you suggest, would be 'leaving the network' to get your contracts (mining) done by external resources to save the gas cost. Which is not possible and violates some of the core principles.