Skip to main content

Web3 Button

The Web3 Button component calls a function on your smart contract when clicked.

import { Web3Button } from "@thirdweb-dev/react";

<Web3Button
contractAddress="<your-smart-contract-address-here>"
action={(contract) =>
contract.erc721.mint({
name: "Hello world!",
})
}
>
Mint NFT
</Web3Button>;

It ensures the following before attempting to call the contract function:

  1. There is a connected wallet (If there is not, renders a ConnectWalletButton component instead).
  2. The connected wallet is on the correct network (as specified in the ThirdwebProvider's desiredChainId).

Props

PropRequiredDescriptionType
contractAddressRequiredThe address of the smart contract to interact withstring
actionRequiredFunction to run when the button is pressed.(contract) => any
contractAbiOptionalProvide the ABI of the smart contract you want to interact withobject, string, or JSON
accentColorOptionalThe background color of the buttonHex Code
colorModeOptionalChange the color of the text inside the buttonlight or dark
onSubmitOptionalRun logic when the action is called() => void
onSuccessOptionalRun logic when the action function finishes successfully(result) => void
onErrorOptionalRun logic when the action function errors(error) => void
isDisabledOptionalDisable the button from being pressedboolean

Examples

Basic

<Web3Button
contractAddress="<your-smart-contract-address-here>"
action={(contract) => console.log(contract)}
colorMode="dark"
accentColor="#ff0000"
>
Print Contract from ABI
</Web3Button>

Using ABI

<Web3Button
contractAddress="<your-smart-contract-address-here>"
contractAbi={"<your-smart-contract-abi-here>"}
action={(contract) => console.log(contract)}
colorMode="dark"
accentColor="#ff0000"
>
Print Contract from ABI
</Web3Button>

Full Example

<Web3Button
contractAddress="<your-smart-contract-address-here>"
contractAbi={"<your-smart-contract-abi-here>"}
action={(contract) => console.log(contract)}
colorMode="dark"
accentColor="#ff0000"
onSubmit={() => console.log("Submitting")}
onSuccess={(result) => console.log("Success", result)}
onError={(error) => console.log("Error", error)}
isDisabled={false}
>
Web3Button
</Web3Button>