Contracts

Deploy Contracts

You can deploy contracts via CLI or programatically.

Deploying via CLI

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

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

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

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

Deploying via SDK

You can deploy contracts from ABI and bytecode.

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.

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
});

Deploy via API

You can also deploy contracts via API by passing the contract bytecode and ABI. This will automatically verify the contract on block explorers and add it to your project dashboard.

Request

fetch("https://api.thirdweb.com/v1/contracts", {
method: "POST",
headers: {
"x-secret-key": "<your-project-secret-key>",
},
body: {
chainId: 1,
from: "0x1234567890123456789012345678901234567890",
bytecode: "0x608060405234801561001057600080fd5b50...",
abi: [
{
type: "constructor",
inputs: [
{
name: "defaultAdmin",
type: "address",
},
],
},
{
type: "function",
name: "name",
inputs: [],
outputs: [
{
type: "string",
},
],
stateMutability: "view",
},
],
constructorParams: {
defaultAdmin: "0x1234567890123456789012345678901234567890",
},
},
});

Response

{
"result": {
"address": "string",
"chainId": 0,
"transactionId": "string"
}
}

List all deployed contracts

You can list all deployed contracts for your project.

Request

fetch("https://api.thirdweb.com/v1/contracts?limit=20&page=1", {
method: "GET",
headers: {
"x-secret-key": "<your-project-secret-key>",
},
});

Response

{
"result": {
"contracts": [
{
"address": "string",
"chainId": "string",
"importedAt": "string",
"deployedAt": "string",
"id": "string",
"name": "string"
}
],
"pagination": {
"hasMore": true,
"limit": 20,
"page": 1
}
}
}