Create Time locked smart contracts where the time is sourced from a Chainlink oracle. A user needs to specify the following to set up the smart contract:
- Amount of XDC to be locked in smart contract
- A date and time at which the locked XDC will be released by the smart contract
- XDC address where the XDC will be sent after it is released by the smart contract
- Overview
- Prerequisite
- Tools & Technologies
- Configuring Chainlink Job
- Deploying Time Locked Contracts
- Configuring the Application
- Building the Application
- Accessing the Application
Time Locked Smart Contract is a feature which allows users to send XDC payments to multiple receivers. These conditional payments, sets the XDC aside and transfers it to receivers when the time has elapsed. After the time has expired, only the intended receivers can get the locked up XDC.
This application requires integration of XDC Network Network with Chainlink. It is recommended to follow XinFin-Chainlink guide and setup all the required applications which includes -
- Chainlink node
- Chainlink - External Initiator
- Deploying LINK token contract
- Deploying Oracle contract
Following tools and technologies have been usse to develop Time Locked Smart Contract application -
- Node.js 12.8 - https://nodejs.org/en/
- Vue.js 4.x - https://v3.vuejs.org/
- Bootstrap 5.x - https://getbootstrap.com/
- web3 / xdc3 1.3.x - https://web3js.readthedocs.io/en/v1.5.2/
- XinPay 6.0.0 - 6.0.0 - https://chrome.google.com/webstore/detail/xinpay/bocpokimicclpaiekenaeelehdjllofo?hl=en
- Chainlink 0.10.x - https://chain.link/
- Solidity 0.4.24 - https://docs.soliditylang.org/en/v0.8.7/
Create an Alarm Job in Chainlink node. Steps to create Alarm Job -
- Login to Chainlink node
- Navigate to Jobs and click on New Job
- Copy the job specification form chainlink/alarm-job.json file
- Paste the contents into the Json Spec field and create the job
- Copy the newly created job ID which we will be using later
Compile and deploy the contracts required for Time Locked Smart Contract creation using remix editor.
- contracts/TimeLockedContractFactory.sol - Factory contract used to create Time Locked Contracts and tracks all the contracts created by users.
- contracts/TimeLockedContract.sol - Contract implementing ChainlinkClient which is responsible for initiating Alarm Job in Chainlink and implements the callback function which will be invoked on time expiry. Stores all the information related to the contract which includes -
- Receivers and corresponding XDC to be locked up
- Unlock date
Deploy the TimeLockedContractFactory using remix editor and take a note of the deployed contract address which we will be using later.
By the end of this step we should have following addresses -
| Keyword | Description |
|---|---|
| TLW_FACTORY_CONTRACT_ADDR | Address of the deployed Time Locked Contract Factory |
| LINK_TOKEN_CONTRACT_ADDR | Address of the deployed LINK token contract |
| ORACLE_CONTRACT_ADDR | Address of the deployed Oracle contract |
| CHAIN_LINK_JOB_ID | Address of the alarm job created in Chainlink node |
--
Before building or running the application following fields values should be replaced in ui/src/assets/js/config.js.
NOTE: Network id 51 refers to XDC Apothem network and 50 refers to XDC Main network
- TLW_FACTORY_CONTRACT_ADDR
- LINK_TOKEN_CONTRACT_ADDR
- ORACLE_CONTRACT_ADDR
- CHAIN_LINK_JOB_ID
-
For local development, run the below command from project root directory and access the application using http://localhost:3000
npm install npm run serve -- --port 3000
-
For production environments, run the below command and once the build is successful final artifacts should be available in dist/ directory
npm run build
docker build -t tlc .
docker run -p 8080:8080 tlc- An account in XDCPay is required to access the application. Users will approve the transaction using XDCPay.
- Make sure the address added in XDCPay has sufficient XDC based on the network being used.
- Add the Link token address in XDCPay wallet and make sure there is sufficient LINK balance.
Displays the list of contracts created by the user with following information -
| Field | Description |
|---|---|
| Contract Address | Address of the Time Locked Contract |
| XDC | Total amount of XDC locked up |
| Created Date | Contract creation date |
| Unlock Date | XDC release date |
| Receivers | Total number of receivers and corresponding XDC locked up |
| Status | Status of the transaction |
User will be provided with following actions based on the contract status -
| Action | Description |
|---|---|
| Transfer Link Token | This option will be available only if LINK token is not transferred to the contract. Using this option LINK token can be transferred to the contract to initiate the Chainlink job |
| Withdraw Contract | This option will be available only if LINK token is not transferred and when contract is not initiated. Using this option user can withdraw the total allocated XDC back to wallet |
Creating Time Locked Contract is a 2 step process, which includes -
- Creating a new Contract
- Transferring the LINK token and initiating Alarm Job in Chainlink
- User specifies the duration of XDC lockup
- Amount of XDC to be allocated to each receiver
On contract creation, XDC will be transferred from user's wallet to the new contract.
In this step, LINK token (Link fee) will be transferred to the created contract. Link fee is required to initiate the job Chainlink job.





