Skip to main content

Example - Timelock Smart Contract

Add Torus Testnet on your browser wallet

Copy the following values in your browser wallet to connect to the Torus Testnet:

PropertyValue
Network nameTorus Testnet
RPC URLhttps://rpc.testnet.toruschain.com
Chain ID8194
Currency SymboltTQF
Block explorer URLhttps://testnet.toruscan.com/

This is what it should look like:

"Torus Testnet Config"

Get testnet funds

Visit the Torus Testnet Faucet to request tQF (testnet QF) funds.

Use RemixIDE

Visit Remix IDE

This is what the Remix IDE interface looks like:

"Remix IDE"

On the left sidebar click on the "Files" tab to open the File Explorer pane.

"File Explorer tab"

On the File Explorer pane you can see some already existing files and directories.

Click the "Create new folder" button and give your new folder a name.

"New folder"

"Naming the new folder"

The "open folder" icon denotes that this folder is currently open.

Click on the "Create new file" button to create a new file in the currently open folder and name your new smart contract file.

"New file"

The new smart contract would be written in solidity language so give the file name the .sol extension.

"Timelock contract

Begin by denoting the license of your code. In this example we use the GPL-3.0 license.

"Contract license"

Now add the solidity compiler requirements. In this example we specify version 0.8.21.

"Solidity version"

Define the contract with the name Timelock

"Define Timelock contract"

The contract needs to store the address of the owner and a timestamp after which the withdrawal functionality is unlocked.

Define two immutable variables. One for the owner address and another for the unlock time.

"immutable variable declaration"

Write the constructor function that instanciates the contract with the deployer's address as the owner and days to unlock as a constructor argument.

"Constructor function"

Create the withdraw function that can only be called after the unlock time has passed. Add require statements to check if the caller is the owner and if current timestamp is greater than unlock time.

"withdraw function require statements"

Add the withdrawal logic

"Withdrawal logic"