diff --git a/packages/thirdweb/README.md b/packages/thirdweb/README.md index 45b0fb74993..498f6e56ab8 100644 --- a/packages/thirdweb/README.md +++ b/packages/thirdweb/README.md @@ -19,6 +19,65 @@ npm install thirdweb@alpha ### Backend (Node, Bun, Deno, etc) +#### With Extensions + +```ts +import { createClient } from "thirdweb"; +import { privateKeyWallet } from "thirdweb/wallets/private-key"; +import { balanceOf, mintTo } from "thirdweb/extensions/erc20"; + +// Step 1: create a client +const client = createClient({ + // create a secret key at https://thirdweb.com/dashboard + secretKey: process.env.SECRET_KEY as string, +}); + +// Step 2: define a contract to interact with +const contract = client.contract({ + // the contract address + address: "0xBCfaB342b73E08858Ce927b1a3e3903Ddd203980", + // the chainId of the chain the contract is deployed on + chainId: 5, +}); + +// Step 3: read contract state +const balance = await balanceOf(contract, { + address: "0x0890C23024089675D072E984f28A93bb391a35Ab", +}); + +console.log("beginning balance", balance); + +// Step 4: initialize a wallet +const wallet = privateKeyWallet(client); + +await wallet.connect({ pkey: process.env.PRIVATE_KEY as string }); + +// Step 5: create a transaction +const tx = mintTo(contract, { + to: "0x0890C23024089675D072E984f28A93bb391a35Ab", + amount: 100, +}); + +// Step 6: execute the transaction with the wallet +const receipt = await wallet.sendTransaction(tx); + +console.log("tx hash", receipt.transactionHash); + +// Step 7: wait for the receipt to be mined +const txReceipt = await receipt.wait(); + +console.log(txReceipt); + +// Step 8: read contract state +const newBalance = await balanceOf(contract, { + address: "0x0890C23024089675D072E984f28A93bb391a35Ab", +}); + +console.log("ending balance", newBalance); +``` + +#### Without Extensions + ```ts import { createClient } from "thirdweb"; import { privateKeyWallet } from "thirdweb/wallets/private-key";