diff --git a/packages/thirdweb/README.md b/packages/thirdweb/README.md index 498f6e56ab8..a9afb2415c6 100644 --- a/packages/thirdweb/README.md +++ b/packages/thirdweb/README.md @@ -26,6 +26,12 @@ import { createClient } from "thirdweb"; import { privateKeyWallet } from "thirdweb/wallets/private-key"; import { balanceOf, mintTo } from "thirdweb/extensions/erc20"; +// Step 1: create a client +import { createClient, contract } from "thirdweb"; +import { privateKeyWallet } from "thirdweb/wallets/private-key"; +import { balanceOf, mintTo } from "thirdweb/extensions/erc20"; +import { waitForReceipt } from "thirdweb/transaction"; + // Step 1: create a client const client = createClient({ // create a secret key at https://thirdweb.com/dashboard @@ -33,7 +39,7 @@ const client = createClient({ }); // Step 2: define a contract to interact with -const contract = client.contract({ +const myContract = contract(client, { // the contract address address: "0xBCfaB342b73E08858Ce927b1a3e3903Ddd203980", // the chainId of the chain the contract is deployed on @@ -41,7 +47,7 @@ const contract = client.contract({ }); // Step 3: read contract state -const balance = await balanceOf(contract, { +const balance = await balanceOf(myContract, { address: "0x0890C23024089675D072E984f28A93bb391a35Ab", }); @@ -53,7 +59,7 @@ const wallet = privateKeyWallet(client); await wallet.connect({ pkey: process.env.PRIVATE_KEY as string }); // Step 5: create a transaction -const tx = mintTo(contract, { +const tx = mintTo(myContract, { to: "0x0890C23024089675D072E984f28A93bb391a35Ab", amount: 100, }); @@ -64,12 +70,12 @@ 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(); +const txReceipt = await waitForReceipt(tx); console.log(txReceipt); // Step 8: read contract state -const newBalance = await balanceOf(contract, { +const newBalance = await balanceOf(myContract, { address: "0x0890C23024089675D072E984f28A93bb391a35Ab", }); @@ -79,7 +85,8 @@ console.log("ending balance", newBalance); #### Without Extensions ```ts -import { createClient } from "thirdweb"; +import { contract, createClient } from "thirdweb"; +import { read, transaction, waitForReceipt } from "thirdweb/transaction"; import { privateKeyWallet } from "thirdweb/wallets/private-key"; // Step 1: create a client @@ -89,7 +96,7 @@ const client = createClient({ }); // Step 2: define a contract to interact with -const contract = client.contract({ +const myContract = contract(client, { // the contract address address: "0xBCfaB342b73E08858Ce927b1a3e3903Ddd203980", // the chainId of the chain the contract is deployed on @@ -97,7 +104,7 @@ const contract = client.contract({ }); // Step 3: read contract state -const balance = await contract.read({ +const balance = await read(myContract, { method: "function balanceOf(address) view returns (uint256)", params: ["0x0890C23024089675D072E984f28A93bb391a35Ab"], }); @@ -107,10 +114,10 @@ console.log("beginning balance", balance); // Step 4: initialize a wallet const wallet = privateKeyWallet(client); -await wallet.connect({ pkey: process.env.PKEY as string }); +await wallet.connect({ pkey: process.env.PRIVATE_KEY as string }); // Step 5: create a transaction -const tx = contract.transaction({ +const tx = transaction(myContract, { method: "function mintTo(address to, uint256 amount)", params: [ "0x0890C23024089675D072E984f28A93bb391a35Ab", @@ -124,12 +131,12 @@ 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(); +const txReceipt = await waitForReceipt(tx); console.log(txReceipt); // Step 8: read contract state -const newBalance = await contract.read({ +const newBalance = await read(myContract, { method: "function balanceOf(address) view returns (uint256)", params: ["0x0890C23024089675D072E984f28A93bb391a35Ab"], });