Web3Button
Button that executes a function on a smart contract from the connected wallet when clicked.
It ensures the following criteria before attempting to call the contract function:
There is a connected wallet (if there is not, it renders a
ConnectWallet
component instead.The connected wallet is on the correct network as specified in the
ThirdwebProvider
'sactiveChain
prop. if it is not, it renders a "switch network" button instead.
If the action you are performing is async, make sure to return a Promise
from the action function so that the SDK knows when the action is complete. This can be done by either using async/await or by returning a Promise
.
Example
import { Web3Button } from "@thirdweb-dev/react";
const App = () => {
return (
<div>
<Web3Button
contractAddress="0x..."
action={(contract) => contract.erc721.transfer("0x...", 1)}
>
Claim NFT
</Web3Button>
</div>
);
};