Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions apps/portal/src/app/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ const links = [
name: "Contracts",
},
{
href: "/insight",
name: "Insight",
},
{
href: "/vault",
name: "Vault",
href: "/tokens",
name: "Tokens",
},
];

Expand Down
57 changes: 57 additions & 0 deletions apps/portal/src/app/contracts/deploy/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Deploy Contracts

You can deploy contracts via CLI or programatically.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo: "programatically" → "programmatically"

There's a spelling error in the word "programatically".

-You can deploy contracts via CLI or programatically.
+You can deploy contracts via CLI or programmatically.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
You can deploy contracts via CLI or programatically.
You can deploy contracts via CLI or programmatically.
🤖 Prompt for AI Agents
In apps/portal/src/app/contracts/deploy/page.mdx at line 3, correct the typo
"programatically" to "programmatically" to fix the spelling error.


## Deploying via CLI

From your forge or hardhat project, you can deploy your contract with a single command.

```bash
npx thirdweb deploy -k <project-secret-key>
```

You can also publish your contract to be deployable by anyone on any chain.

```bash
npx thirdweb publish -k <project-secret-key>
```



## Deploying via SDK

You can deploy contracts from ABI and bytecode.

```ts
import { deployContract } from "thirdweb/deploys";

const address = await deployContract({
client,
chain,
bytecode: "0x...",
abi: contractAbi,
constructorParams: {
param1: "value1",
param2: 123,
},
salt, // optional: salt enables deterministic deploys
});
```

Or alternatively, you can deploy a contract from a previously published contract.

```ts
import { deployPublishedContract } from "thirdweb/deploys";

const address = await deployPublishedContract({
client,
chain,
account,
contractId: "MyPublishedContract",
contractParams: {
param1: "value1",
param2: 123,
},
publisher: "0x...", // optional, defaults to the thirdweb deployer
});
```
40 changes: 40 additions & 0 deletions apps/portal/src/app/contracts/events/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Listening to Events

The recommended way to listen to contract events is to use the [`getContractEvents`](/references/typescript/v5/getContractEvents) function and passing a prepared event with the Solidity event signature and the params. This is type-safe based on the Solidity event signature you define. You can get your desired contract event signature from the solidity code directly.

```ts
import { getContractEvents, prepareEvent } from "thirdweb";

const myEvent = prepareEvent({
signature: "event Transfer(address indexed from, address indexed to, uint256 value)",
});

const events = await getContractEvents({
contract: myContract,
events: [myEvent],
});
```
Comment on lines +8 to +16
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing contract definition in code example.

The example uses myContract without defining it, which could confuse readers.

 import { getContractEvents, prepareEvent } from "thirdweb";
+import { getContract } from "thirdweb";
+import { ethereum } from "thirdweb/chains";
+
+const myContract = getContract({
+  client,
+  chain: ethereum,
+  address: "0x...", // your contract address
+});

 const myEvent = prepareEvent({
   signature: "event Transfer(address indexed from, address indexed to, uint256 value)",
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const myEvent = prepareEvent({
signature: "event Transfer(address indexed from, address indexed to, uint256 value)",
});
const events = await getContractEvents({
contract: myContract,
events: [myEvent],
});
```
import { getContractEvents, prepareEvent } from "thirdweb";
import { getContract } from "thirdweb";
import { ethereum } from "thirdweb/chains";
const myContract = getContract({
client,
chain: ethereum,
address: "0x...", // your contract address
});
const myEvent = prepareEvent({
signature: "event Transfer(address indexed from, address indexed to, uint256 value)",
});
const events = await getContractEvents({
contract: myContract,
events: [myEvent],
});
🤖 Prompt for AI Agents
In apps/portal/src/app/contracts/events/page.mdx around lines 8 to 16, the code
example uses the variable myContract without defining it, which can confuse
readers. Add a definition or initialization of myContract before it is used in
getContractEvents, ensuring it is clear what myContract represents and how it is
obtained or created.


### Using standard event definitions

You can also use the standard event definitions from the SDK to define the events you want to listen to.

```ts
import { getContractEvents } from "thirdweb";
import { transferEvent } from "thirdweb/extensions/erc20";

const events = await getContractEvents({
contract: myContract,
events: [transferEvent()],
});
```
Comment on lines +26 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing contract definition for consistency.

Similar to the previous example, myContract is used without definition.

 import { getContractEvents } from "thirdweb";
 import { transferEvent } from "thirdweb/extensions/erc20";
+import { getContract } from "thirdweb";
+import { ethereum } from "thirdweb/chains";
+
+const myContract = getContract({
+  client,
+  chain: ethereum, 
+  address: "0x...", // your ERC20 contract address
+});

 const events = await getContractEvents({
   contract: myContract,
   events: [transferEvent()],
 });

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In apps/portal/src/app/contracts/events/page.mdx around lines 26 to 30, the
variable myContract is used without being defined, causing inconsistency and
potential errors. Define myContract before its usage by importing or
initializing it appropriately, ensuring it matches the contract setup used in
previous examples for consistency.


### Generating all read functions and events for a deployed contract

Using the CLI, you can generate optimized functions for all the possible calls to a contract. This saves you time and precomputes all the necessary encoding.

```shell
npx thirdweb generate <contractId>/<contractAddress>
```
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

CLI command parameter format needs clarification.

The command uses <contractId>/<contractAddress> but the parameter should likely be <chainId>/<contractAddress> based on the generate page example.

-npx thirdweb generate <contractId>/<contractAddress>
+npx thirdweb generate <chainId>/<contractAddress>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
npx thirdweb generate <contractId>/<contractAddress>
```
npx thirdweb generate <chainId>/<contractAddress>
🤖 Prompt for AI Agents
In apps/portal/src/app/contracts/events/page.mdx around lines 37 to 38, the CLI
command parameter is incorrectly labeled as <contractId>/<contractAddress>.
Update the parameter to <chainId>/<contractAddress> to match the correct format
shown in the generate page example, ensuring clarity and consistency in the
documentation.


Read more on how to [generate extension functions using the CLI](/contracts/generate).
85 changes: 85 additions & 0 deletions apps/portal/src/app/contracts/extensions/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { fetchTypeScriptDoc } from "@/app/references/components/TDoc/fetchDocs/fetchTypeScriptDoc";
import { getCustomTag } from "@/app/references/components/TDoc/utils/getSidebarLinkgroups";
import { DocLink, Heading, Paragraph } from "@/components/Document";
import { Table, TBody, Td, Th, Tr } from "@/components/Document/Table";

export default async function ExtensionPage() {
const docs = await fetchTypeScriptDoc();
const extensions = [
...new Set(
docs.functions
?.filter((f) => {
const [extension] = getCustomTag(f) || [];
return extension === "@extension";
})
?.map((f) => {
const [, extensionName] = getCustomTag(f) || [];
return extensionName;
})
.filter((item) => item !== undefined) || [],
),
];

const overrides: Record<string, { name?: string; description?: string }> = {
common: {
description: "Common contract extensions",
name: "Common",
},
erc20: { description: "ERC20 token standard extensions" },
erc721: { description: "ERC721 token standard extensions" },
erc1155: { description: "ERC1155 token standard extensions" },
erc4337: { description: "ERC4337 account abstraction extensions" },
erc4626: { description: "ERC4626 Tokenized Vaults extensions" },
farcaster: { description: "Farcaster protocol extensions" },
lens: { description: "Lens protocol extensions" },
};
return (
<>
<Heading anchorId="built-in-extensions" level={1}>
Built-in extensions for common standards
</Heading>
<Paragraph>
The SDK comes packed with a set of built-in extensions for common
standards. These extensions are designed to make it easy to interact
with popular contracts and protocols. They are available as part of the
SDK and can be used in your application without any additional setup.
</Paragraph>
<Table>
<TBody>
<Tr>
<Th>Standard</Th>
<Th>Import Path</Th>
<Th>Description</Th>
</Tr>

{extensions.map((item) => {
return (
<Tr key={item}>
<Td>{overrides[item]?.name ?? item}</Td>
<Td>
<DocLink
href={`/references/typescript/v5/functions#${item.toLowerCase()}`}
>
thirdweb/extensions/{item.toLowerCase()}
</DocLink>
</Td>
<Td>{overrides[item]?.description ?? `${item} extensions`}</Td>
</Tr>
);
})}
</TBody>
</Table>
<Paragraph>
More extensions are being added regularly. Anyone can{" "}
<DocLink href="/typescript/v5/extensions/create">
create an extension
</DocLink>{" "}
and contribute it back to the repository. You can also{" "}
<DocLink href="/typescript/v5/extensions/generate">
generate extensions
</DocLink>{" "}
for any deployed contract.
</Paragraph>
</>
);
}
69 changes: 69 additions & 0 deletions apps/portal/src/app/contracts/generate/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Generating extensions

You can generate precompiled, optimized extensions for any deployed contract using the thirdweb CLI.

The thirdweb SDK comes with a CLI that can be run with your package manager of choice.

```bash
npx thirdweb generate <chainId>/<contract-address>
```

This will generate a new `thirdweb` directory in your own project, containing the precompiled extension for the contract at the given address.

### Example: Generating an extension for a USDC contract on Optimism

```bash
npx thirdweb generate 10/0x0b2c639c533813f4aa9d7837caf62653d097ff85
```

This will generate the following file `thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85.ts` in your project, containing:

- Precompiled, type-safe event definitions
- Precompiled, type-safe function definitions

You can inspect the generated code, modify it, and use it in your project.

### Example: Using a generated extension function

```typescript
import { permit } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";

const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});

Comment on lines +31 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing imports in code example.

The code example uses getContract, optimism, and USDC_ADDRESS without showing their imports, which could confuse developers.

+import { getContract } from "thirdweb";
+import { optimism } from "thirdweb/chains";
 import { permit } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";

+const USDC_ADDRESS = "0x0b2c639c533813f4aa9d7837caf62653d097ff85";
+
 const contract = getContract({
 	client,
 	chain: optimism,
 	address: USDC_ADDRESS,
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});
import { getContract } from "thirdweb";
import { optimism } from "thirdweb/chains";
import { permit } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";
const USDC_ADDRESS = "0x0b2c639c533813f4aa9d7837caf62653d097ff85";
const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});
🤖 Prompt for AI Agents
In apps/portal/src/app/contracts/generate/page.mdx around lines 31 to 36, the
code example uses getContract, optimism, and USDC_ADDRESS without importing
them. Add the appropriate import statements for getContract, optimism, and
USDC_ADDRESS at the top of the code example to clarify their origins and avoid
confusion for developers.

// Type-safe function to do a permit transaction
const transaction = permit({
owner: ...,
spender: ...,
value: ...,
deadline: ...,
signature: ...,
});
await sendTransaction({ transaction, account });
Comment on lines +38 to +45
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Complete the permit function example with proper TypeScript types.

The permit function call has incomplete parameters with ellipsis, and sendTransaction is used without imports or proper context.

+import { sendTransaction } from "thirdweb";
+
 // Type-safe function to do a permit transaction
 const transaction = permit({
-  owner: ...,
-  spender: ...,
-  value: ...,
-  deadline: ...,
-  signature: ...,
+  owner: "0x...", // owner address
+  spender: "0x...", // spender address  
+  value: 1000000n, // amount in token units
+  deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
+  signature: "0x...", // EIP-712 signature
 });
 await sendTransaction({ transaction, account });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const transaction = permit({
owner: ...,
spender: ...,
value: ...,
deadline: ...,
signature: ...,
});
await sendTransaction({ transaction, account });
import { sendTransaction } from "thirdweb";
// Type-safe function to do a permit transaction
const transaction = permit({
owner: "0x...", // owner address
spender: "0x...", // spender address
value: 1000000n, // amount in token units
deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour from now
signature: "0x...", // EIP-712 signature
});
await sendTransaction({ transaction, account });
🤖 Prompt for AI Agents
In apps/portal/src/app/contracts/generate/page.mdx around lines 38 to 45, the
permit function call uses incomplete parameters with ellipsis and
sendTransaction is used without import or context. Replace the ellipsis with
actual parameter values typed according to the permit function's TypeScript
signature, ensuring all required fields like owner, spender, value, deadline,
and signature are properly typed and provided. Also, add the necessary import
statement for sendTransaction at the top of the file or provide its definition
to ensure it is recognized and used correctly.

```

### Example: Using a generated event

```typescript
import { transferEvent } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";

const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});

Comment on lines +53 to +58
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing imports for event example.

Similar to the previous example, this code uses undefined imports.

+import { getContract, getContractEvents } from "thirdweb";
+import { optimism } from "thirdweb/chains";
 import { transferEvent } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";

+const USDC_ADDRESS = "0x0b2c639c533813f4aa9d7837caf62653d097ff85";
+
 const contract = getContract({
 	client,
 	chain: optimism,
 	address: USDC_ADDRESS,
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});
import { getContract, getContractEvents } from "thirdweb";
import { optimism } from "thirdweb/chains";
import { transferEvent } from "/thirdweb/10/0x0b2c639c533813f4aa9d7837caf62653d097ff85";
const USDC_ADDRESS = "0x0b2c639c533813f4aa9d7837caf62653d097ff85";
const contract = getContract({
client,
chain: optimism,
address: USDC_ADDRESS,
});
🤖 Prompt for AI Agents
In apps/portal/src/app/contracts/generate/page.mdx around lines 53 to 58, the
code uses variables or functions like getContract, optimism, and USDC_ADDRESS
without importing them. Add the necessary import statements at the top of the
file to define these identifiers, ensuring all dependencies are properly
imported to avoid reference errors.

// Type-safe event listener
const events = await getContractEvents({
contract,
events: [
transferEvent({
from: ...,
to: ...,
})
],
});
```
6 changes: 3 additions & 3 deletions apps/portal/src/app/contracts/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default async function Layout(props: { children: React.ReactNode }) {

export const metadata = createMetadata({
description:
"Easily create, deploy, and manage smart contracts on any EVM compatible blockchain",
"Easily read, write, deploy, and listen to contract events on any EVM compatible blockchain",
image: {
icon: "contract",
title: "thirdweb contracts",
title: "Contracts",
},
title: "thirdweb Contracts",
title: "Contracts",
});
Loading
Loading