Skip to content

Commit fbb5f0a

Browse files
committed
get invoking smart contract working
1 parent 2166616 commit fbb5f0a

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

packages/plugin-coinbase/src/plugins/tokenContract.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,21 @@ export const invokeContractAction: Action = {
340340
return;
341341
}
342342

343-
const { contractAddress, method, args, amount, assetId, network } =
343+
const { contractAddress, method, args, amount, assetId, networkId } =
344344
invocationDetails.object;
345-
346-
const wallet = await initializeWallet(runtime, network);
345+
const wallet = await initializeWallet(runtime, networkId);
347346

348347
// Prepare invocation options
349348
const invocationOptions = {
350349
contractAddress,
351350
method,
352351
abi: ABI,
353-
args,
354-
...(amount && assetId ? { amount, assetId } : {}),
352+
args: {
353+
...args,
354+
amount: args.amount || amount // Ensure amount is passed in args
355+
},
356+
networkId,
357+
assetId
355358
};
356359
elizaLogger.log("Invocation options:", invocationOptions);
357360
// Invoke the contract
@@ -379,7 +382,7 @@ export const invokeContractAction: Action = {
379382
[
380383
contractAddress,
381384
method,
382-
network,
385+
networkId,
383386
invocation.getStatus(),
384387
invocation.getTransactionLink() || "",
385388
amount || "",
@@ -392,7 +395,7 @@ export const invokeContractAction: Action = {
392395
text: `Contract method invoked successfully:
393396
- Contract Address: ${contractAddress}
394397
- Method: ${method}
395-
- Network: ${network}
398+
- Network: ${networkId}
396399
- Status: ${invocation.getStatus()}
397400
- Transaction URL: ${invocation.getTransactionLink() || "N/A"}
398401
${amount ? `- Amount: ${amount}` : ""}
@@ -417,7 +420,7 @@ Contract invocation has been logged to the CSV file.`,
417420
{
418421
user: "{{user1}}",
419422
content: {
420-
text: " Call the 'transfer' method on my ERC20 token contract at 0x37f2131ebbc8f97717edc3456879ef56b9f4b97b with amount 100 to recepient 0xbcF7C64B880FA89a015970dC104E848d485f99A3",
423+
text: "Call the 'transfer' method on my ERC20 token contract at 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 with amount 100 to recepient 0xbcF7C64B880FA89a015970dC104E848d485f99A3",
421424
},
422425
},
423426
{

packages/plugin-coinbase/src/templates.ts

+22-11
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,19 @@ Extract the following details for invoking a smart contract using the Coinbase S
173173
- **method** (string): The method to invoke on the contract
174174
- **abi** (array): The ABI of the contract
175175
- **args** (object, optional): The arguments to pass to the contract method
176-
- **amount** (number, optional): The amount of the asset to send to a payable contract method
177-
- **assetId** (string, optional): The ID of the asset to send to a payable contract method
178-
- **network** (string): The blockchain network to use (e.g., base, eth, arb, pol)
176+
- **amount** (string, optional): The amount of the asset to send (as string to handle large numbers)
177+
- **assetId** (string, required): The ID of the asset to send (e.g., 'USDC')
178+
- **networkId** (string, required): The network ID to use in format "chain-network".
179+
static networks: {
180+
readonly BaseSepolia: "base-sepolia";
181+
readonly BaseMainnet: "base-mainnet";
182+
readonly EthereumHolesky: "ethereum-holesky";
183+
readonly EthereumMainnet: "ethereum-mainnet";
184+
readonly PolygonMainnet: "polygon-mainnet";
185+
readonly SolanaDevnet: "solana-devnet";
186+
readonly SolanaMainnet: "solana-mainnet";
187+
readonly ArbitrumMainnet: "arbitrum-mainnet";
188+
};
179189
180190
Provide the details in the following JSON format:
181191
@@ -187,17 +197,17 @@ Provide the details in the following JSON format:
187197
"args": {
188198
"<arg_name>": "<arg_value>"
189199
},
190-
"amount": <amount>,
200+
"amount": "<amount_as_string>",
191201
"assetId": "<asset_id>",
192-
"network": "<network>"
202+
"networkId": "<network_id>"
193203
}
194204
\`\`\`
195205
196-
Example for invoking a transfer method on an ERC20 token contract:
206+
Example for invoking a transfer method on the USDC contract:
197207
198208
\`\`\`json
199209
{
200-
"contractAddress": "0x37f2131ebbc8f97717edc3456879ef56b9f4b97b",
210+
"contractAddress": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
201211
"method": "transfer",
202212
"abi": [
203213
{
@@ -208,7 +218,7 @@ Example for invoking a transfer method on an ERC20 token contract:
208218
"type": "address"
209219
},
210220
{
211-
"name": "value",
221+
"name": "amount",
212222
"type": "uint256"
213223
}
214224
],
@@ -225,10 +235,11 @@ Example for invoking a transfer method on an ERC20 token contract:
225235
}
226236
],
227237
"args": {
228-
"to": "0xRecipientAddressHere",
229-
"value": 1000
238+
"to": "0xbcF7C64B880FA89a015970dC104E848d485f99A3",
239+
"amount": "1000000" // 1 USDC (6 decimals)
230240
},
231-
"network": "eth"
241+
"networkId": "ethereum-mainnet",
242+
"assetId": "USDC"
232243
}
233244
\`\`\`
234245

packages/plugin-coinbase/src/types.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@ export interface ContractInvocationContent {
124124
method: string;
125125
abi: any[];
126126
args?: Record<string, any>;
127-
amount?: number;
128-
assetId?: string;
129-
network: string;
127+
amount?: string;
128+
assetId: string;
129+
networkId: string;
130130
}
131131

132132
export const ContractInvocationSchema = z.object({
133133
contractAddress: z.string().describe("The address of the contract to invoke"),
134134
method: z.string().describe("The method to invoke on the contract"),
135135
abi: z.array(z.any()).describe("The ABI of the contract"),
136136
args: z.record(z.string(), z.any()).optional().describe("The arguments to pass to the contract method"),
137-
amount: z.number().optional().describe("The amount of the asset to send to a payable contract method"),
138-
assetId: z.string().optional().describe("The ID of the asset to send to a payable contract method"),
139-
network: z.string().describe("The blockchain network to use"),
137+
amount: z.string().optional().describe("The amount of the asset to send (as string to handle large numbers)"),
138+
assetId: z.string().describe("The ID of the asset to send (e.g., 'USDC')"),
139+
networkId: z.string().describe("The network ID to use (e.g., 'ethereum-mainnet')")
140140
});
141141

142142
export const isContractInvocationContent = (obj: any): obj is ContractInvocationContent => {

0 commit comments

Comments
 (0)