1

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()
0

I would recommend you to take some time, face this problems one by one and search if they have already been answered.
If not, make a detailed but simple question for each one of them.

People that know much more than me will be able to help you but right now you have multiple questions in one and its very confusing. Just trying to help.

By the way:

  • Im sure you can do the 'fee' in the contract, if I remember where I saw an example I will comment again.
  • Depending the case, but usually I believe that its better to reuse the contract.
0

Of course you can use the same contract for all transactions. In fact it's meant yo be used this way. You only deploy it once and all transactions are run by the same contract.

You need to clarify what do you mean by "my website address" because the way you have it written the "fee" will remain in the contract. You would need to still transfer the fee to your "website".

What I see in your code though is that you don't validate if the "values" are in any way related to the amount of ETH transferred by whoever has invoked this function. This is where your contract will fall apart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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