Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add readContract / invokeContract functionality to Coinbase plugin #923

Merged

Conversation

monilpat
Copy link
Collaborator

@monilpat monilpat commented Dec 8, 2024

Features

Contract Interactions

  • Introduced readContractAction for reading data from deployed smart contracts
  • Added ReadContractContent interface and ReadContractSchema for input validation
  • Integrated readContractTemplate to guide users in extracting necessary details for read operations
  • Enhanced existing contract interaction capabilities in tokenContractPlugin with invokeContractAction now relying on networkId, amount as a string, and required assetId

Technical Details

New Types

interface ReadContractContent {
    contractAddress: `0x${string}`;
    method: string;
    networkId: string; // Network now identified by networkId (e.g. "ethereum-mainnet")
    args?: Record<string, any>;
    abi?: any[];
}
  • ReadContractSchema added for validating read operations:
    • Validates contractAddress, method, networkId, args, and optional abi

Updated Invocation Schema

  • network replaced by networkId to align with Coinbase SDK requirements
  • amount now handled as a string to support large values without precision loss
  • assetId is now required for payable contract methods

Templates

  • readContractTemplate: Guides extracting details (contractAddress, method, networkId, args, abi) for reading contract data
  • tokenContractTemplate & contractInvocationTemplate: Enhanced for clarity and alignment with updated schema fields

Actions

  • readContractAction: Reads data (view/pure methods) from deployed smart contracts
  • invokeContractAction: Invokes contract methods; updated to use networkId, amount as a string, and a required assetId
  • deployTokenContractAction: Deploys token contracts as before, now compatible with the updated schemas

Testing

Contract Reading

  • Tested reading ERC20 balances and contract state variables
  • Validated network support via networkId
  • Ensured error handling for invalid contracts, addresses, and unsupported networks

Invocation and Deployment

  • Confirmed invocation succeeds with the updated networkId approach
  • Verified that amount as a string and mandatory assetId don't break existing flows

Reading contract:
Screenshot 2024-12-08 at 2 36 12 PM

Invoking contract:

https://drive.google.com/file/d/16VtpCI7q8J4opco9jQO3XQdwZMb0u-Yz/view?usp=sharing

Risks

  • Low: Reading contract data is read-only, minimal risk
  • Medium: Contract invocation involves real transactions
    • Mitigation: Added balance checks, improved error handling, and validation through ReadContractSchema

Documentation

  • Documentation updated to reflect new readContractAction, networkId field, and schema changes
  • Added examples showcasing how to read contract data and invoke contract methods with the new parameters

Deploy Notes

  • No database changes required
  • Compatible with existing configurations
  • Requires adjustments to references of network to networkId in configurations and calls
  • Ensure Coinbase API credentials are properly set before reading or invoking contracts

- Introduced a new action `readContractAction` to read data from deployed smart contracts using the Coinbase SDK.
- Added `ReadContractContent` interface and `ReadContractSchema` for validation.
- Updated templates to include a `readContractTemplate` for user guidance.
- Enhanced the `tokenContractPlugin` description to reflect the new reading capabilities.
@monilpat monilpat marked this pull request as ready for review December 8, 2024 23:46
Copy link
Contributor

@pgoos pgoos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @monilpat . LGTM 🚀

@jkbrooks jkbrooks merged commit a26bf19 into elizaOS:main Dec 9, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants