eliza
eliza copied to clipboard
feat: add readContract / invokeContract functionality to Coinbase plugin
Features
Contract Interactions
- Introduced
readContractActionfor reading data from deployed smart contracts - Added
ReadContractContentinterface andReadContractSchemafor input validation - Integrated
readContractTemplateto guide users in extracting necessary details for read operations - Enhanced existing contract interaction capabilities in
tokenContractPluginwithinvokeContractActionnow relying onnetworkId,amountas a string, and requiredassetId
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[];
}
ReadContractSchemaadded for validating read operations:- Validates
contractAddress,method,networkId,args, and optionalabi
- Validates
Updated Invocation Schema
networkreplaced bynetworkIdto align with Coinbase SDK requirementsamountnow handled as a string to support large values without precision lossassetIdis now required for payable contract methods
Templates
readContractTemplate: Guides extracting details (contractAddress, method, networkId, args, abi) for reading contract datatokenContractTemplate&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,amountas a string, and a requiredassetId - 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
networkIdapproach - Verified that
amountas a string and mandatoryassetIddon't break existing flows
Reading contract:
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
- Mitigation: Added balance checks, improved error handling, and validation through
Documentation
- Documentation updated to reflect new
readContractAction,networkIdfield, 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
networktonetworkIdin configurations and calls - Ensure Coinbase API credentials are properly set before reading or invoking contracts