SynaptiQ Systems
  • Welcome SynaptiQ Systems
  • Getting Started
    • Overview: SynaptiQ Systems
    • Installation Guide: SynaptiQ Systems
  • Basics
    • YAML Configuration Filentitled
    • Modular Architecture: SynaptiQ Systems
    • Swarm Behavior: SynaptiQ Systems
    • SwarmConsensus: Collaborative Decision-Making in SynaptiQ Systems
    • Dynamic Breeding in SynaptiQ Systems
    • Democratic Decision-Making in SynaptiQ Systems
  • Multi-Agent Collaboration in SynaptiQ Systems
  • AI Agent in SynaptiQ Systems
  • Reinforcement Learning (Self-Optimization) in SynaptiQ Systems
  • IPFS for Decentralized Messaging in SynaptiQ Systems
  • Integrations in SynaptiQ Systems
  • Database and Storage Integrations
  • Blockchain Smart Contract Interaction
  • Blockchain Integration
  • Knowledge Graph Integration
  • Advanced Use Cases
  • API Documentation
  • Glossary
  • Output Overview
  • Security Practices
  • Roadmap
  • FAQ
  • Proof of Concept: Aether SynaptiQ Systems in Action
  • Github
Powered by GitBook
On this page

Blockchain Smart Contract Interaction

Blockchain Smart Contract Interaction

Overview

SynaptiQ Systems includes built-in support for interacting with blockchain smart contracts. This feature enables agents to execute trustless, verifiable actions such as task logging, resource allocation, and decentralized governance.

The framework supports Ethereum and Solana, with additional functionality for deploying, calling, and managing smart contracts.

Key Features

  • Smart Contract Deployment: Deploy contracts directly from agents to enable automation and on-chain verification.

  • Function Invocation: Call contract functions to perform tasks or retrieve data.

  • On-Chain Task Logging: Record task results securely for auditing and collaboration.

  • Multi-Chain Support: Use Ethereum for complex computations and Solana for high-speed, low-cost transactions.

Examples

1. Deploying a Smart Contract

Agents can deploy smart contracts on Ethereum to automate tasks and establish secure workflows.

Code Example:

pythonCopy codefrom src.utils.blockchain_manager import BlockchainManager

# Initialize the Blockchain Manager
blockchain = BlockchainManager()

# Define contract ABI and Bytecode
abi = [
    {
        "constant": True,
        "inputs": [],
        "name": "getValue",
        "outputs": [{"name": "", "type": "uint256"}],
        "payable": False,
        "stateMutability": "view",
        "type": "function",
    }
]
bytecode = "0x608060405234801561001057600080fd5b5060405161010038038061010083398101806040528101908080518201929190505050806000819055505060d58061003e6000396000f3fe6080604052600080fdfea165627a7a723058202cfa2cf67d..."

# Deploy the smart contract
contract_address = blockchain.deploy_contract(abi, bytecode)
print(f"Smart contract deployed at: {contract_address}")

2. Calling a Smart Contract Function

Once deployed, agents can interact with the contract's functions to retrieve or modify on-chain data.

Code Example:

pythonCopy code# Call a function from the deployed contract
result = blockchain.call_contract_function(contract_address, abi, "getValue")
print(f"Contract result: {result}")

3. Logging Tasks on the Blockchain

Agents can log task results on-chain for secure, immutable storage and auditing.

Code Example:

pythonCopy code# Log a task result on-chain
transaction_hash = blockchain.log_task(
    sender_keypair="path/to/solana_keypair.json",
    task_description="Analyze energy consumption data",
    task_result="Task completed successfully"
)
print(f"Task logged on blockchain. Transaction hash: {transaction_hash}")

Wallet Configuration

To interact with blockchains, agents need to securely configure wallets. Use environment variables to store sensitive information like wallet paths and private keys.

Solana Wallet

Set the wallet path using the SOLANA_WALLET_PATH environment variable:

Code Example:

bashCopy codeSOLANA_WALLET_PATH=/path/to/solana-wallet.json

Ethereum Wallet

Set the private key using the ETHEREUM_WALLET_PRIVATE_KEY environment variable:

Code Example:

bashCopy codeETHEREUM_WALLET_PRIVATE_KEY=your_private_key_here

Accessing Wallets in Code

Code Example:

pythonCopy codeimport os

# Load Solana wallet path
solana_wallet_path = os.getenv("SOLANA_WALLET_PATH")
print(f"Solana Wallet Path: {solana_wallet_path}")

# Load Ethereum private key
ethereum_private_key = os.getenv("ETHEREUM_WALLET_PRIVATE_KEY")
print("Ethereum Private Key Loaded.")

Common Use Cases

  • Task Verification: Deploy contracts to verify that tasks were executed correctly.

  • Resource Allocation: Use contracts to manage on-chain resource distribution.

  • Decentralized Governance: Implement voting mechanisms for swarm decision-making.


Common Issues and Solutions

Problem

Solution

FileNotFoundError: Wallet path not found.

Ensure the SOLANA_WALLET_PATH environment variable is correctly set.

ValueError: Ethereum private key missing.

Add the ETHEREUM_WALLET_PRIVATE_KEY variable to your environment.

Contract deployment failed.

Verify the RPC URL, ensure sufficient gas fees, and check for ABI/bytecode errors.


Best Practices

  • Always use environment variables to manage sensitive information like private keys.

  • For high-security applications, encrypt wallets and only decrypt them during runtime.

  • Test smart contracts thoroughly on testnets (e.g., Ethereum’s Goerli or Solana’s Devnet) before deploying to mainnets.

  • Use multi-signature wallets for tasks involving significant resources or sensitive data.

PreviousDatabase and Storage IntegrationsNextBlockchain Integration

Last updated 5 months ago