I'm learning about smart contracts currently and a bit confused as to how they really work.
My website allows users to send ETH from their wallet on site to another address off site. During which I'd like to deduct 1% for a fee on my website.
Is it possible via smart contracts to do this?
What I've done now using solidity is this developed this very basic contract:
pragma solidity ^0.4.18;
contract MultiSend
{
function multiSendETH(address[] memory addresses, uint[] memory values) public payable
{
// Validate addresses and values match
if(addresses.length != values.length)
{
return;
}
else
{
for(uint i = 0; i < addresses.length; i++)
{
address(addresses[i]).transfer(values[i]);
}
msg.sender.transfer(this.balance);
}
}
}
I have deployed it with a value of 1 wei via remix.ethereum.org successfully.
Is it possible to reuse the same smart contract over and over again everytime someone makes a withdraw from my website?
Or do I have to create the smart contract with a value equal to that of what is being withdrawn?
My issue is the smart contract takes a bit to get mined and become available so doing that method of funding it with the proper value being withdrawn and the time span to when the contract is available and can be executed will have some delay and be bad for user experience.
I was hoping it would be possible to reuse this smart contract and maybe add in a parameter of which wallet to send from? Is that possible?
Also is it possible to get the transaction ID from this line:
address(addresses[i]).transfer(values[i]);
Or is my understanding of smart contracts completely off?
I'd like to call this like:
addresses = ['0xTheirOutputAddress', '0xMySiteAddress']
fee = total * 0.01
values = [total - fee, fee]
w3.contract.multiSendETH(addresses, values).call()