Skip to content

Commit 4f346e6

Browse files
docs: update read-contract usage examples and explanations (#5001)
1 parent f9f5365 commit 4f346e6

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

packages/thirdweb/src/transaction/read-contract.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,16 @@ export type ReadContractOptions<
7272
/**
7373
* ### Reads state from a deployed smart contract.
7474
*
75-
* You can use raw read calls or read [extensions](https://portal.thirdweb.com/typescript/v5/extensions/use) to read from a contract.
75+
* Use this for raw read calls from a contract, but you can also use read [extensions](https://portal.thirdweb.com/typescript/v5/extensions/use) for predefined methods for common standards.
7676
*
7777
* @param options - The transaction options.
7878
* @returns A promise that resolves with the result of the read call.
7979
* @transaction
8080
* @example
8181
*
82-
* ### Using a contract read extension
82+
* ### Raw contract call (recommended)
8383
*
84-
* ```ts
85-
* import { getContract } from "thirdweb";
86-
* import { sepolia } from "thirdweb/chains";
87-
* import { useReadContract } from "thirdweb/react";
88-
* import { getOwnedNFTs } form "thirdweb/extensions/erc721";
89-
*
90-
* const contract = getContract({
91-
* client,
92-
* address: "0x...",
93-
* chain: sepolia,
94-
* });
95-
*
96-
* const { data, isLoading } = useReadContract(getOwnedNFTs, { contract, owner: address });
97-
* ```
98-
*
99-
* ### Using a raw contract call
84+
* You can read from any contract by using the solidity signature of the function you want to call.
10085
*
10186
* ```ts
10287
* import { getContract } from "thirdweb";
@@ -116,7 +101,14 @@ export type ReadContractOptions<
116101
* });
117102
* ```
118103
*
119-
* ### Using `resolveMethod`
104+
* Note that this is type safe, the params types will be enforced based on the signature.
105+
*
106+
* ### Raw contract call with `resolveMethod`
107+
*
108+
* If you don't have the solidity signature of the function you want to call, you can use the `resolveMethod` helper to resolve the method from any deployed contract.
109+
*
110+
* Note that this is not type safe, and will also have a 1 time overhead of resolving the contract ABI.
111+
*
120112
* ```ts
121113
* import { getContract, resolveMethod } from "thirdweb";
122114
* import { sepolia } from "thirdweb/chains";

0 commit comments

Comments
 (0)