-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make SDK factory client patterns #353
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8e0e966
add protocol sdk and minting features
iainnash 37da3bd
Merge remote-tracking branch 'origin/main' into rename_protocol_sdk
iainnash 51951fa
undo changes to other package
iainnash 1f08bbc
fix build
iainnash a22b027
Adding automated anvil testing client creation. (#324)
iainnash 3df5240
protocol sdk updates
iainnash f6b70d8
Instead of having the clients write the transaction, have them prepar…
oveddan c083d5a
merge main
iainnash e234505
rename
oveddan e60c980
Rename some params for better understanding what they mean
oveddan 384d118
update mintable data path
iainnash 2bc63d7
update chain renames
iainnash 5e4b6fa
Example of returning prepared tx from mint client (#334)
oveddan 831b9ed
merge fix
iainnash 215511a
merge fix
iainnash 28070ef
Adding automated anvil testing client creation.
iainnash bba8a69
finalize all testing
iainnash 4e94bda
fix build
iainnash ba94282
update code pattern
iainnash 08efa92
small updates
iainnash cffccff
merge conflict fix
iainnash f8bfc7f
fix merge conflicts
iainnash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,15 @@ Protocol SDK allows users to manage zora mints and collects. | |
### Creating a mint from an on-chain contract: | ||
|
||
```ts | ||
import { MintAPI } from "@zoralabs/protocol-sdk"; | ||
import { createMintClient } from "@zoralabs/protocol-sdk"; | ||
import type { Address, WalletClient } from "viem"; | ||
|
||
async function mintNFT( | ||
walletClient: WalletClient, | ||
address: Address, | ||
tokenId: bigint, | ||
) { | ||
const mintAPI = new MintAPI(walletClient.chain); | ||
const mintAPI = createMintClient({ chain: walletClient.chain }); | ||
await mintAPI.mintNFT({ | ||
walletClient, | ||
address, | ||
|
@@ -33,18 +33,49 @@ async function mintNFT( | |
} | ||
``` | ||
|
||
### Creating an 1155 contract: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx for adding this! |
||
|
||
If an object with {name, uri} is passed in to this helper, it uses the creatorAccount and those values to either 1) create or 2) mint to that existing contract. | ||
|
||
If you wish to mint on an existing contract, pass that contract in the contract field. The return value is the prepared transaction that you can use viem or wagmi to send. | ||
|
||
```ts | ||
import type { PublicClient } from "viem"; | ||
import { create1155CreatorClient } from "@zoralabs/protocol-sdk"; | ||
|
||
export async function createContract({ | ||
publicClient, | ||
walletClient, | ||
}: { | ||
publicClient: PublicClient; | ||
walletClient: WalletClient; | ||
}) { | ||
const creatorClient = create1155CreatorClient({ publicClient }); | ||
const { request } = await creatorClient.createNew1155Token({ | ||
contract: { | ||
name: "testContract", | ||
uri: demoContractMetadataURI, | ||
}, | ||
tokenMetadataURI: demoTokenMetadataURI, | ||
account: creatorAccount, | ||
mintToCreatorCount: 1, | ||
}); | ||
const { request: simulateRequest } = publicClient.simulateContract(request); | ||
const hash = await walletClient.writeContract(simulateRequest); | ||
const receipt = await publicClient.waitForTransactionReceipt({ hash }); | ||
return receipt; | ||
} | ||
``` | ||
|
||
### Creating a premint: | ||
|
||
```ts | ||
import { PremintAPI } from "@zoralabs/protocol-sdk"; | ||
import type { Address, WalletClient } from "viem"; | ||
|
||
async function makePremint(walletClient: WalletClient) { | ||
// Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently). | ||
const premintAPI = new PremintAPI(walletClient.chain); | ||
|
||
// Create premint | ||
const premint = await premintAPI.createPremint({ | ||
const premint = await createPremintAPI(walletClient.chain).createPremint({ | ||
// Extra step to check the signature on-chain before attempting to sign | ||
checkSignature: true, | ||
// Collection information that this premint NFT will exist in once minted. | ||
|
@@ -76,7 +107,7 @@ import type { Address, WalletClient } from "viem"; | |
|
||
async function updatePremint(walletClient: WalletClient) { | ||
// Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently). | ||
const premintAPI = new PremintAPI(walletClient.chain); | ||
const premintAPI = createPremintAPI(walletClient.chain); | ||
|
||
// Create premint | ||
const premint = await premintAPI.updatePremint({ | ||
|
@@ -105,7 +136,7 @@ import type { Address, WalletClient } from "viem"; | |
|
||
async function deletePremint(walletClient: WalletClient) { | ||
// Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently). | ||
const premintAPI = new PremintAPI(walletClient.chain); | ||
const premintAPI = createPremintClient({ chain: walletClient.chain }); | ||
|
||
// Create premint | ||
const premint = await premintAPI.deletePremint({ | ||
|
@@ -132,7 +163,7 @@ async function executePremint( | |
premintAddress: Address, | ||
premintUID: number, | ||
) { | ||
const premintAPI = new PremintAPI(walletClient.chain); | ||
const premintAPI = createPremintClient({ chain: walletClient.chain }); | ||
|
||
return await premintAPI.executePremintWithWallet({ | ||
data: premintAPI.getPremintData(premintAddress, premintUID), | ||
|
@@ -146,12 +177,12 @@ async function executePremint( | |
|
||
### Deleting a premint: | ||
|
||
```js | ||
```ts | ||
import {PremintAPI} from '@zoralabs/premint-sdk'; | ||
import type {Address, WalletClient} from 'viem'; | ||
|
||
async function deletePremint(walletClient: WalletClient, collection: Address, uid: number) { | ||
const premintAPI = new PremintAPI(walletClient.chain); | ||
const premintAPI = createPremintClient({chain: walletClient.chain}); | ||
|
||
return await premintAPI.deletePremint({ | ||
walletClient, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor:
const mintAPI
should becost mintClient