5. Setup and start Eliza agent
Where are we?

Eliza-Starter is a template from Eliza framework to allow developers to create characters, clients and plugins. In this starter, a plugin called GetGift is created to call functions consumer smart contract deployed in previous steps.
Steps to setup and start Eliza
Let's get ready to use the Eliza AI Agent Framework with the GetGift Eliza plugin by following steps:
Git clone the repo: `git clone https://github.com/smartcontractkit/Eliza-Twitter-Chainlink-Functions.git` Then change directory into the
Eliza-Twitter-Chainlink-Functionsproject folder and run.
Check the
.env.examplefile and make sure your.envfile has all the indicated environment variables. We will need the Google Gemini key, evm private key and avalanche fuji rpc url set correctly in the.env.
Update variables in action implementation file
getGift.ts(repo link)
Open the file src/custom-plugins/actions/getGift.ts, and paste in the necessary configurations which are marked as TODOs. To make the actions to send transactions as we requested, these constants must be updated:
contractAddress: the address of Functions consumer smart contract. Update the value with contract you added to the the Chainlink Functions subscription.donHostedSecretsSlotId: the slot ID for secret saved in the DON. If you did not modify the script in last step, assign the default one to the the constant. The default value is0.donHostedSecretsVersion: the version of secret saved in the DON you uploaded in last step. You can find the value in your Remix IDE terminal. In last step, you have already uploaded secret to the DON, when making the request, you must pass thedonHostedSecretsSlotIdanddonHostedSecretsVersionto tell the DON where to fetch the encrypted secrets. Both of these things should be printed to your Remix IDE terminal from the upload secrets step.clSubId: Chainlink Functions Subscription ID. Update the value to the subscription ID you created on the Functions Dashboard App.
Let's understand the code
getGift.ts implements a custom ElizaOS Action for interacting with a Chainlink Functions consumer contract on the Avalanche Fuji testnet. Here's a breakdown of its main components:
In GetGiftAction Class, core functionalities to interact with the smart contract are implemented, and wallet provider which is a wrapper of viem used to handle blockchain interactions. Within the class, the function getGift parses parameters and extract gift and grantee's address and then make a call to the hardcoded smart contract with necessary data.
The other exported object is Action getGiftAction which is the "configuration" of the plugin. The plugin is registered with agent as an entry to make the action.
After config info updated, run the agent with default character using the following command (⚠️ remember to check that your using node V23 or higher!)
If your AI agent start successfully, you will see the info below:

Ask for a NFT gift
Have your wallet address and one of the 3 gift codes ready. Then type your request in natural language - use can use the following template:
please send the gift to: <<YOUR_WALLET>> My gift code is: <<GIFT_CODE_IN_DATABASE>>
Type this into your terminal as show below:

Check the responses
The AI agent will process the request and return the message and transaction hash. You will the see the info below:

Check the Chainlink Functions app
After the action in AI agent is processed, a transaction is sent to the Functions consumer smart contract deployed before. The contract constructs a new Functions request with gift ID and send to the DON, and the the request is displayed on Functions.app.

Check if a NFT minted for a specific address
Go to the Opensea for testnet to check if you have a new NFT. Paste the address of your GetGiftcontract into the OpenSea search bar, and you can see the NFT(s) minted to your address!
Please be noticed that the same gift codes cannot be redeemed twice which means you cannot have the duplicated gift on the address.

Last updated