0

I am going through a tutorial and just need some clarification on the below code - particularly the second line. Could someone take me through this very slowly?


    function deposit() public payable {}

    function depositOnContractOne(address _contractOne) public { 
        ContractOne one = ContractOne(_contractOne);
        one.deposit{value: 10, gas: 100000}(); 
    }

1 Answer 1

1

The line

ContractOne one = ContractOne(_contractOne);

creates an instance of the ContractOne and names it 'one'. So in 'one' is all the functions that are in 'ContractOne'.

The next line

one.deposit{value: 10, gas: 100000}(); 

calls the deposit function from the ContractOne. The deposit() function in ContractOne must be external and payable since there is some value attached to it.

So, to summarize, your function 'depositOnContractOne' instantiates a 'ContractOne' at address '_contractOne' and names it 'one', then send 10 wei while calling the function 'deposit' of 'ContractOne'.

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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