Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Learn how to use the Web3Button component from the thirdweb React SDK!
Web3Button is a Next.js boilerplate that demonstrates how to use the thirdweb React SDK's Web3Button component to call any function on any smart contract while automatically handling wallet connection and network switching.
Web3Button is a starter template built on Next.js and the thirdweb React SDK. It takes a smart contract address and an action (or a function name and parameters) as input, and executes the contract call only after verifying that the user's wallet is connected and the active network matches the one configured in _app.js. The template outputs a working React component that renders a customizable button, with callbacks for success and error states.
_app.js file of the Next.js project.action function that receives the contract instance, or pass a functionName and params array to call any contract method directly.onSuccess and onError props so you can handle the transaction result or display errors.colorMode and accentColor props for light/dark mode and accent color theming._app.js network configuration pattern.mintTo function with an address and metadata (name, image, description) directly from the button action.functionName and params to invoke arbitrary methods without writing a custom action.onSuccess callback to confirm the transaction hash or trigger a UI update; use onError to log issues.The template relies on the Web3Button component from the thirdweb React SDK. You supply the contractAddress and either an action function (which receives the contract and can call any method) or a functionName plus params list. The component then checks wallet connection and network, executes the call, and triggers the corresponding callback. The network is set globally in _app.js, so every button instance uses the same chain.
No, the component is designed to require a connected wallet. It ensures a wallet is connected before executing the contract function, which is standard for on-chain transactions.
Yes, the label is provided as children of the Web3Button component. In the example, the button displays 'Mint NFT'.
The template itself is an open-source example provided in the repository. The underlying thirdweb SDK has its own pricing model, but this template does not require payment.
The network is defined in the _app.js file of the Next.js project. The exact chain is not shown in the snippet, but it is configurable there.
