Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsdls committed Jan 23, 2024
1 parent 1dacfba commit 87b98d8
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions packages/thirdweb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@ 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
secretKey: process.env.SECRET_KEY as string,
});

// 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
chainId: 5,
});

// Step 3: read contract state
const balance = await balanceOf(contract, {
const balance = await balanceOf(myContract, {
address: "0x0890C23024089675D072E984f28A93bb391a35Ab",
});

Expand All @@ -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,
});
Expand All @@ -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",
});

Expand All @@ -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
Expand All @@ -89,15 +96,15 @@ 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
chainId: 5,
});

// Step 3: read contract state
const balance = await contract.read({
const balance = await read(myContract, {
method: "function balanceOf(address) view returns (uint256)",
params: ["0x0890C23024089675D072E984f28A93bb391a35Ab"],
});
Expand All @@ -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",
Expand All @@ -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"],
});
Expand Down

0 comments on commit 87b98d8

Please sign in to comment.