TLDR:
Unlike legacy finance systems, where you need to rely on a well-established third party, you can build your own financial instrument on Ethereum.
The objective of this tutorial is to show how easy it is to build and run your own instance of a simple decentralized finance example, or DeFi.
In this tutorial, you will:
Create a basic Trust Fund account smart contract with the following interaction options:
Compile the smart contract with Remix IDE.
Deploy the smart contract to the Ethereum Sepolia testnet through a Chainstack node.
Interact with the smart contract through Remix IDE and a Chainstack node.
For illustration purposes, this tutorial uses Ethereum Sepolia testnet.
For Ethereum mainnet, the steps are exactly the same, except you need to use mainnet ether.
To get from zero to a deployed Trust Fund account on the Ethereum Sepolia testnet, do the following:
With Chainstack, create a .
With Chainstack, join the Ethereum Sepolia testnet.
With Chainstack, access your Ethereum node credentials.
Set up your MetaMask to work through a Chainstack node.
With Remix IDE, create and compile the Trust Fund smart contract.
Set up your Remix IDE to work through a Chainstack node.
With Remix IDE, deploy the contract to the Ethereum Sepolia testnet.
With Remix IDE, interact with the contract on the Ethereum Sepolia testnet.
See Create a project.
See View node access and credentials.
See Ethereum tooling: MetaMask.
Having set up your MetaMask to interact through a Chainstack node, your Remix IDE will also interact with the network through a Chainstack node.
Create at least two accounts in MetaMask. You need two accounts to transfer the contract ownership from one to another.
In your MetaMask, fund each account with Sepolia ether Chainstack’s Sepolia faucet.
Open Remix IDE.
On the home page, click Environments > Solidity.
On the left pane, click File explorers > +.
In the modal, give any name to your contract. For example, transferableTrustFund.sol
.
Put in the contract code:
This is your Trust Fund account smart contract:
The contract belongs to the Ethereum account that deploys the contract through:
The onlyOwner
modifier is used to restrict access to certain functions in the smart contract to only the owner of the contract. A modifier is like a wrapper that can be applied to a function, and it modifies the behavior of the function in some way:
Only the contract owner can withdraw all funds from the contract through:
Only the contract owner can withdraw partial funds from the contract through:
Anyone can deposit funds to the contract through:
Only the contract owner can transfer the contract ownership to any other Ethereum account through:
Retrieve the current balance on the smart contract and the current owner with:
Compile the contract. On the left pane, click Solidity compiler > Compile:
If the contract does not compile, make sure to change the compiler version to 0.8.0 or higher.
On the left pane, click Deploy and switch to Injected Provider - Metamask:
This will engage your MetaMask and interact with the network through the Chainstack node provided in MetaMask.
On the left pane, click Deploy & run transactions > Deploy:
This will engage your MetaMask to deploy the contract to the Ethereum Sepolia testnet through your currently selected MetaMask account. Click Confirm in the MetaMask modal.
Once the contract is deployed, fund the contract:
Now that your contract is funded, you can interact with it.
Expand the contract under Deployed Contracts:
withdrawAmount
— enter any amount that is less than the current contract balance to withdraw partial funds.withdrawAll
— click to withdraw all funds from the contract.transferAccount
— enter any Ethereum address to transfer the contract ownership. For this example, enter the address of your second account in MetaMask.getBalance
— click to display the current ether balance in the smart contract; the balance is shown in Wei.getOwner
— click to display the address currently owning the Trust fund smart contract.TLDR:
Unlike legacy finance systems, where you need to rely on a well-established third party, you can build your own financial instrument on Ethereum.
The objective of this tutorial is to show how easy it is to build and run your own instance of a simple decentralized finance example, or DeFi.
In this tutorial, you will:
Create a basic Trust Fund account smart contract with the following interaction options:
Compile the smart contract with Remix IDE.
Deploy the smart contract to the Ethereum Sepolia testnet through a Chainstack node.
Interact with the smart contract through Remix IDE and a Chainstack node.
For illustration purposes, this tutorial uses Ethereum Sepolia testnet.
For Ethereum mainnet, the steps are exactly the same, except you need to use mainnet ether.
To get from zero to a deployed Trust Fund account on the Ethereum Sepolia testnet, do the following:
With Chainstack, create a .
With Chainstack, join the Ethereum Sepolia testnet.
With Chainstack, access your Ethereum node credentials.
Set up your MetaMask to work through a Chainstack node.
With Remix IDE, create and compile the Trust Fund smart contract.
Set up your Remix IDE to work through a Chainstack node.
With Remix IDE, deploy the contract to the Ethereum Sepolia testnet.
With Remix IDE, interact with the contract on the Ethereum Sepolia testnet.
See Create a project.
See View node access and credentials.
See Ethereum tooling: MetaMask.
Having set up your MetaMask to interact through a Chainstack node, your Remix IDE will also interact with the network through a Chainstack node.
Create at least two accounts in MetaMask. You need two accounts to transfer the contract ownership from one to another.
In your MetaMask, fund each account with Sepolia ether Chainstack’s Sepolia faucet.
Open Remix IDE.
On the home page, click Environments > Solidity.
On the left pane, click File explorers > +.
In the modal, give any name to your contract. For example, transferableTrustFund.sol
.
Put in the contract code:
This is your Trust Fund account smart contract:
The contract belongs to the Ethereum account that deploys the contract through:
The onlyOwner
modifier is used to restrict access to certain functions in the smart contract to only the owner of the contract. A modifier is like a wrapper that can be applied to a function, and it modifies the behavior of the function in some way:
Only the contract owner can withdraw all funds from the contract through:
Only the contract owner can withdraw partial funds from the contract through:
Anyone can deposit funds to the contract through:
Only the contract owner can transfer the contract ownership to any other Ethereum account through:
Retrieve the current balance on the smart contract and the current owner with:
Compile the contract. On the left pane, click Solidity compiler > Compile:
If the contract does not compile, make sure to change the compiler version to 0.8.0 or higher.
On the left pane, click Deploy and switch to Injected Provider - Metamask:
This will engage your MetaMask and interact with the network through the Chainstack node provided in MetaMask.
On the left pane, click Deploy & run transactions > Deploy:
This will engage your MetaMask to deploy the contract to the Ethereum Sepolia testnet through your currently selected MetaMask account. Click Confirm in the MetaMask modal.
Once the contract is deployed, fund the contract:
Now that your contract is funded, you can interact with it.
Expand the contract under Deployed Contracts:
withdrawAmount
— enter any amount that is less than the current contract balance to withdraw partial funds.withdrawAll
— click to withdraw all funds from the contract.transferAccount
— enter any Ethereum address to transfer the contract ownership. For this example, enter the address of your second account in MetaMask.getBalance
— click to display the current ether balance in the smart contract; the balance is shown in Wei.getOwner
— click to display the address currently owning the Trust fund smart contract.