Curently minimal transaction cost is around 0.1$. And it's VERY high for most of IoT applications, where service price is less than 0,1$.
Is there any solutions, works, startups anything about it?
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 communityCurently minimal transaction cost is around 0.1$. And it's VERY high for most of IoT applications, where service price is less than 0,1$.
Is there any solutions, works, startups anything about it?
You want payment channels or state channels in general (payment channel is a type of state channel).
Payment channels
A payment channel works like in roughly three phases (see this post for more details/context):
Open a new channel with a sender and a recipient
function OpenChannel(address token, address to, uint amount) {
if (amount == 0) { throw; }
if (to == msg.sender) { throw; }
if (active_ids[msg.sender][to] != bytes32(0)) { throw; }
bytes32 id = sha3(msg.sender, to, now);
Channel memory _channel;
_channel.deposit = amount;
_channel.sender = msg.sender;
_channel.recipient = to;
_channel.token = token;
ERC20 t = ERC20(token);
if (!t.transferFrom(msg.sender, address(this), amount)) { throw; }
channels[id] = _channel;
active_ids[msg.sender][to] = id;
}
Sign messages from sender to recipient. These messages contain a value
, which can be verifiably sent to the recipient at any time.
var sha3 = require('solidity-sha3').default;
var _value = 0.01*Math.pow(10, 18)
var value = _value.toString(16)
let _msg_hash = sha3(`0x${channel_id}`, _value);
let msg_hash = Buffer.from(_msg_hash.substr(2, 64), 'hex');
let sig = util.ecsign(msg_hash, keys.test.privateKey);
let parsed_sig = {
v: sig.v.toString(16),
r: sig.r.toString('hex'),
s: sig.s.toString('hex')
};
latest_value = value;
latest_sig = parsed_sig;
latest_msg_hash = msg_hash.toString('hex')
Close the channel. This is a transaction that takes one of the above signed messages and plays it on chain. This will transfer that messages funds to the recipient and delete the channel.
function CloseChannel(bytes32[4] h, uint8 v, uint256 value) {
// h[0] Channel id
// h[1] Hash of (id, value)
// h[2] r of signature
// h[3] s of signature
// Grab the channel in question
if (channels[h[0]].deposit == 0) { throw; }
Channel memory _channel;
_channel = channels[h[0]];
if (msg.sender != _channel.sender && msg.sender != _channel.recipient) { throw; }
address signer = ecrecover(h[1], v, h[2], h[3]);
if (signer != _channel.sender) { throw; }
// Make sure the hash provided is of the channel id and the amount sent
bytes32 proof = sha3(h[0], value);
// Ensure the proof matches, send the value, send the remainder, and delete the channel
if (proof != h[1]) { throw; }
else if (value > _channel.deposit) { throw; }
// Pay recipient and refund sender the remainder
ERC20 t = ERC20(_channel.token);
if (!t.transfer(_channel.recipient, value)) { throw; }
else if (!t.transfer(_channel.sender, _channel.deposit-value)) { throw; }
// Close the channel
delete channels[h[0]];
delete active_ids[_channel.sender][_channel.recipient];
}
Gas Considerations
Note that a single token transfer costs 50,000 gas. As you have pointed out, this is cost prohibitive for a microtransaction context (although the exact dollar amount depends on the gasPrice
used). A payment channel costs roughly 250,000 gas to open and 250,000 gas to close, depending on the implementation.
This means that a payment channel's overhead is roughly 10 transactions, but if you expect 10,000 micropayments per deposit, that's a cost savings of 1000x.