I followed a tutorial and coded this contract:
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract Trust {
struct Kid {
uint amount;
uint maturity;
bool paid;
}
mapping(address => Kid) public kids;
address public admin;
constructor() {
admin = msg.sender;
}
function addKid(address kid, uint timeToMaturity) external payable {
require(msg.sender == admin, 'only admin can add children');
require(kids[kid].amount == 0, 'this child already exists in the system');
kids[kid] = Kid(msg.value, block.timestamp + timeToMaturity, false);
}
function withdraw() external {
Kid storage kid = kids[msg.sender];
// if the amount is 0, that means it is one of the default mapping addresses
require(kid.amount > 0, 'only active and verified kids can withdraw');
require(kid.maturity <= block.timestamp, 'too early');
require(kid.paid == false, "that kid's address has already been paid");
kid.paid = true;
payable(msg.sender).transfer(kid.amount);
}
}
My question is: once the admin sends some eth to the Kid
struct via the addKid()
function where is that eth stored? The flow of the contract is, the deploying address can add kid structs to the contract and simultaneously fund the kid structs with ETH. But, after running a few tests I've noticed that the ETH doesn't show up in the newly added wallet until I run the withdraw()
function.
Do Smart Contracts have a wallet themselves that can be utilized? Also, if it helps at all I'm using Remix for my development environment.
I'm new to smart contracts but would like to learn more so any tips would be appreciated. Thanks.