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);
Call a payable method
To call a payable method and send the native currency with your transaction (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
Coming soon.
To override the estimated gas settings for your transaction, set txOverrides.gasLimit
and txOverrides.gasPrice
in the request body to POST /contract/<chain>/<contract_address>/write
.
{
functionName: "...",
args: [ ... ],
txOverrides: {
gasLimit: 150000,
gasPrice: 22000000000, // 22 gwei in wei
}
}
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);