Contracts

Call or deploy contracts from your backend wallet to any EVM blockchain with one API call.

Write to a contract

This request requires gas funds in the backend wallet.

const resp = await fetch(
"<engine_url>/contract/<chain>/<contract_address>/write",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <access_token>",
"x-backend-wallet-address": "<backend_wallet_address>",
},
body: JSON.stringify({
functionName: "transferFrom",
args: [
"0x1946267d81Fb8aDeeEa28e6B98bcD446c8248473",
"0x3EcDBF3B911d0e9052b64850693888b008e18373",
"0",
],
}),
},
);
const { result } = await resp.json();
// queueId is a reference to the transaction queued by Engine.
console.log("Queue ID:", result.queueId);

See API reference

Call a payable method

To send native tokens to a payable method (e.g. ETH on Ethereum), set txOverrides.value in the request body to POST /contract/<chain>/<contract_address>/write.

{
functionName: "...",
args: [ ... ],
txOverrides: {
value: 1000000000000000, // 0.001 ETH in wei
}
}

Override gas settings

To override the gas settings for your transaction, set txOverrides in the request body to any write transaction. Each of these fields are optional and will be estimated by Engine if omitted.

{
functionName: "...",
args: [ ... ],
txOverrides: {
// The limit of gas units to use for this transaction.
gas: "530000",
// The max fee (e.g. gas price) to use in wei.
maxFeePerGas: "1000000000",
// The max priority fee to use in wei.
maxPriorityFeePerGas: "1000000000",
}

Read from a contract

const resp = await fetch(
"<engine_url>/contract/<chain>/<contract_address>/read?functionName=balanceOf&args=0x3EcDBF3B911d0e9052b64850693888b008e18373",
{
headers: {
Authorization: "Bearer <access_token>",
},
},
);
const { result } = await resp.json();
console.log("ERC-20 balance:", result);

Deploy a contract

This request requires gas funds in the backend wallet.

const resp = await fetch(
"<engine_url>/deploy/<chain>/prebuilts/nft-drop",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer <access_token>",
"x-backend-wallet-address": "<backend_wallet_address>",
},
body: JSON.stringify({
contractMetadata: {
name: "thirdweb Engine example",
symbol: "eng",
primary_sale_recipient:
"0x3EcDBF3B911d0e9052b64850693888b008e18373",
},
}),
},
);
const { result } = await resp.json();
// queueId is a reference to the transaction queued by Engine.
console.log("Queue ID:", result.queueId);