Onchain AI composability - AI Powered Wallet
In this example, we will demonstrate how to build a simple AI-powered wallet utilizing the LLAMA model deployed on the Base blockchain. This will be accomplished in a few easy steps.
Step 1: implement the suspiciousTransaction
function
suspiciousTransaction
functionThis function queries the on-chain LLAMA model to determine whether a transaction the wallet is about to make is suspicious. The prompt sent to the model is constructed using the wallet's transaction history and the details of the transfer. Providing this context allows the model to respond more accurately.
Step 2: implement the send
function
send
functionThe send
function takes the _inferenceId
generated in the previous step as an argument. It retrieves the inference result provided by the LLAMA model's miners and uses it to determine whether the transaction is suspicious. If the transaction is deemed safe, its details are stored in the wallet's context for use in future transactions.
The complete example code is available at: https://github.com/eternalai-org/eternal-ai/tree/master/examples/AIPoweredWallet
You can run the code with the following command:
Note:
Replace
<PRIVATE_KEY>
with your actual wallet private key. Ensure that the wallet has sufficient ETH on the Base network to cover transaction fees and amounts.Replace
<RECEIVER_ADDRESS>
with another wallet address. While the receiver address does not necessarily have to be the same for all transactions created by the wallet, it is exposed as an environment variable to simplify running the code.
Below is an example of three transactions (two safe and one suspicious) created using our wallet on the Base network:
The wallet 0xAaAa26FbC6b28bf16929Ea216f4700dFCC11A159 attempted to send 0.01 ETH to 0xDEA1Bfc89102138cc90C32B4c9e0e2a970548B09
Inference Transaction: View on BaseScan
LLAMA Miner's Response: View on BaseScan
Send Transaction: View on BaseScan
The wallet 0xAaAa26FbC6b28bf16929Ea216f4700dFCC11A159 attempted to send 0.012 ETH to 0x529F45532C429F02Fb9FE1A5E43b11E80b720Fb0
Inference Transaction: View on BaseScan
LLAMA Miner's Response: View on BaseScan
Send Transaction: View on BaseScan
The wallet 0xAaAa26FbC6b28bf16929Ea216f4700dFCC11A159 attempted to send 0.000001 ETH to 0xEa7d4Bf0a8e4904f32045862eEDC91B261F53f99
Inference Transaction: View on BaseScan
LLAMA Miner's Response: View on BaseScan
In this example, the first and second transactions were evaluated as "safe" by the model. However, the third transaction was flagged as "suspicious" (and its Send transaction was rejected by Base's mempool) because its send amount was significantly smaller than the amounts in previous transactions.
Last updated