From 4fc77553cfee8a555a24cd1267a2a8033123b869 Mon Sep 17 00:00:00 2001 From: rohan-agarwal-coinbase Date: Fri, 18 Oct 2024 21:49:54 -0400 Subject: [PATCH] Updating readContract args to take in any for the value (#300) --- CHANGELOG.md | 5 +++++ package.json | 2 +- quickstart-template/package.json | 2 +- src/coinbase/read_contract.ts | 9 +++++---- src/coinbase/types/contract.ts | 14 +++++++------- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98d69a30..f28b95b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## [0.9.1] - 2024-10-18 + +### Fixed +- Fixed a bug where readContract was not working for nested types + ## [0.9.0] - 2024-10-17 ### Added diff --git a/package.json b/package.json index fc3c4760..81255375 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "ISC", "description": "Coinbase Platform SDK", "repository": "https://github.com/coinbase/coinbase-sdk-nodejs", - "version": "0.9.0", + "version": "0.9.1", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { diff --git a/quickstart-template/package.json b/quickstart-template/package.json index 1fa4b042..43884c1d 100644 --- a/quickstart-template/package.json +++ b/quickstart-template/package.json @@ -22,7 +22,7 @@ "dependencies": { "@solana/web3.js": "^2.0.0-rc.1", "bs58": "^6.0.0", - "@coinbase/coinbase-sdk": "^0.9.0", + "@coinbase/coinbase-sdk": "^0.9.1", "csv-parse": "^5.5.6", "csv-writer": "^1.6.0", "viem": "^2.21.6" diff --git a/src/coinbase/read_contract.ts b/src/coinbase/read_contract.ts index 4cf3fb79..6e5691cb 100644 --- a/src/coinbase/read_contract.ts +++ b/src/coinbase/read_contract.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type { Abi } from "abitype"; import { Coinbase } from "./coinbase"; import { ContractFunctionName } from "viem"; @@ -109,12 +110,12 @@ function parseSolidityValue(solidityValue: SolidityValue): T { * @param {TFunctionName} params.method - The contract method to call. * @param {TArgs} params.args - The arguments for the contract method. * @param {TAbi} [params.abi] - The contract ABI (optional). - * @returns {Promise} The result of the contract call. + * @returns {Promise} The result of the contract call. */ export async function readContract< TAbi extends Abi | undefined, TFunctionName extends TAbi extends Abi ? ContractFunctionName : string, - TArgs extends Record, + TArgs extends Record, >(params: { networkId: string; contractAddress: `0x${string}`; @@ -128,7 +129,7 @@ export async function readContract< Extract>, TArgs > - : unknown + : any > { const response = await Coinbase.apiClients.smartContract!.readContract( params.networkId, @@ -147,6 +148,6 @@ export async function readContract< Extract>, TArgs > - : unknown + : any >(response.data); } diff --git a/src/coinbase/types/contract.ts b/src/coinbase/types/contract.ts index dce02174..4b739d19 100644 --- a/src/coinbase/types/contract.ts +++ b/src/coinbase/types/contract.ts @@ -12,7 +12,7 @@ import { ContractFunctionName } from "viem"; * Each parameter name becomes a key in the resulting dictionary, with a string value. */ type AbiParametersToDictionary = { - [K in T[number]["name"] as K extends string ? K : never]: string; + [K in T[number]["name"] as K extends string ? K : any]: string; }; /** @@ -38,9 +38,9 @@ type MatchArgsToFunction< ? TFunctions extends AbiFunction ? MatchesParams> extends true ? TFunctions - : never - : never - : never; + : any + : any + : any; /** * Determines the return type of a contract function based on the ABI, function name, and arguments. @@ -68,6 +68,6 @@ export type ContractFunctionReturnType< : TOutputs extends readonly [infer TOutput] ? TOutput : TOutputs - : never - : unknown - : unknown; + : any + : any + : any;