-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Example * remove extra tsconfig lines * dedupe
- Loading branch information
Showing
14 changed files
with
466 additions
and
181 deletions.
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
strict-peer-dependencies=false | ||
shared-workspace-lockfile=true | ||
prefer-workspace-packages=true | ||
|
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@soundxyz/sdk-example", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"prepare": "node pull-env.mjs", | ||
"snoop-xyz": "bob-tsm src/snoop-xyz.ts", | ||
"mint": "bob-tsm src/mint.ts" | ||
}, | ||
"dependencies": { | ||
"@soundxyz/sdk": "workspace:^", | ||
"@soundxyz/sound-protocol": "^1.4.0", | ||
"alchemy-sdk": "^2.6.2", | ||
"date-fns": "^2.29.3", | ||
"ethers": "^5.7.2", | ||
"require-env-variable": "^4.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.15.11", | ||
"bob-tsm": "^1.1.2", | ||
"dotenv": "^16.0.3", | ||
"esbuild": "^0.17.15", | ||
"typescript": "5.0.3", | ||
"undici": "^5.21.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { promises } from 'fs' | ||
import { fetch } from 'undici' | ||
|
||
await fetch('https://vault.dotenv.org/pull.txt', { | ||
method: 'POST', | ||
body: 'DOTENV_VAULT=vlt_4011aac495b93f704eea755ec8deba6c5eac6f1a6af55ba645a32b3015dce13c&DOTENV_ME=it_a106570406176c5a9233bd477704bd3c863b660e00cbd4f179023a11714cec70', | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded', | ||
}, | ||
}) | ||
.then((response) => response.text()) | ||
.then((env) => promises.writeFile('.env', env)) |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'dotenv/config' | ||
|
||
import { Alchemy, Network } from 'alchemy-sdk' | ||
import { requireEnv } from 'require-env-variable' | ||
|
||
const { PUBLIC_ALCHEMY_KEY } = requireEnv('PUBLIC_ALCHEMY_KEY') | ||
|
||
export const alchemyMainnetClient = new Alchemy({ | ||
apiKey: PUBLIC_ALCHEMY_KEY, | ||
network: Network.ETH_MAINNET, | ||
}) | ||
|
||
export const alchemyGoerliClient = new Alchemy({ | ||
apiKey: PUBLIC_ALCHEMY_KEY, | ||
network: Network.ETH_GOERLI, | ||
}) | ||
|
||
export const [mainnetProvider, goerliProvider] = await Promise.all([ | ||
alchemyMainnetClient.config.getProvider(), | ||
alchemyGoerliClient.config.getProvider(), | ||
]) |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { SoundClient } from '@soundxyz/sdk' | ||
|
||
import { mainnetProvider } from './alchemy' | ||
|
||
export const clientMainnetProvider = SoundClient({ | ||
provider: mainnetProvider, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import './fetch' | ||
|
||
import { SoundClient } from '@soundxyz/sdk' | ||
import { LanyardMerkleProofProvider } from '@soundxyz/sdk/merkle/lanyard' | ||
|
||
import { goerliProvider } from './alchemy' | ||
import { signer } from './signer' | ||
|
||
export const clientSigner = SoundClient({ | ||
provider: goerliProvider, | ||
signer, | ||
merkleProvider: LanyardMerkleProofProvider, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { fetch } from 'undici' | ||
|
||
// @ts-expect-error Incomplete spec not needed for examples | ||
globalThis.fetch ||= fetch |
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import assert from 'assert' | ||
|
||
import { clientSigner } from './clientSigner' | ||
import { signer } from './signer' | ||
import { goerliProvider } from './alchemy' | ||
import { fromUnixTime } from 'date-fns' | ||
|
||
const exampleEditionAddress = '0xFC6Bdee583f3738F69FeeF4BaCf9069aC086Ad77' | ||
|
||
const editionContract = clientSigner.edition.info({ | ||
contractAddress: exampleEditionAddress, | ||
}).contract | ||
|
||
const editionInfo = await editionContract.info | ||
|
||
assert.strictEqual(editionInfo.name, 'SDK Example') | ||
|
||
console.log(editionInfo) | ||
|
||
assert.strictEqual(editionInfo.mintConcluded, false) | ||
|
||
const { schedules, activeSchedules } = await clientSigner.edition.mintSchedules({ | ||
editionAddress: exampleEditionAddress, | ||
}) | ||
|
||
assert.strictEqual(activeSchedules.length, 2, 'Unexpected amount of schedules') | ||
assert.strictEqual(schedules.length, 2, 'Unexpected amount of schedules') | ||
|
||
assert.deepStrictEqual(schedules, activeSchedules) | ||
|
||
const [merkleDrop, openEditionDrop] = activeSchedules | ||
|
||
assert(merkleDrop?.mintType === 'MerkleDrop', "Unexpected first example drop isn't merkle") | ||
|
||
assert(openEditionDrop?.mintType === 'RangeEdition', "Unexpected second example drop isn't range edition") | ||
|
||
assert( | ||
(await clientSigner.edition.eligibleQuantity({ | ||
mintSchedule: merkleDrop, | ||
userAddress: signer.address, | ||
})) > 0, | ||
"Example account can't collect from presale anymore", | ||
) | ||
|
||
const currentlyOwnedNumberOfTokens = await clientSigner.edition.numberOfTokensOwned({ | ||
editionAddress: exampleEditionAddress, | ||
userAddress: signer.address, | ||
}) | ||
|
||
console.log( | ||
`Wallet ${signer.address} currently owns ${currentlyOwnedNumberOfTokens} tokens. Trying to buy another one from a merkle drop...`, | ||
) | ||
|
||
{ | ||
const mintTransaction = await clientSigner.edition.mint({ | ||
mintSchedule: merkleDrop, | ||
quantity: 1, | ||
}) | ||
|
||
console.log('Mint transaction has been sent, waiting for completion...') | ||
|
||
const receipt = await mintTransaction.wait() | ||
|
||
const confirmedDate = fromUnixTime((await goerliProvider.getBlock(receipt.blockNumber)).timestamp) | ||
|
||
console.log( | ||
`Mint has been confirmed at ${confirmedDate}. Now wallet ${ | ||
signer.address | ||
} owns ${await clientSigner.edition.numberOfTokensOwned({ | ||
editionAddress: exampleEditionAddress, | ||
userAddress: signer.address, | ||
})}`, | ||
) | ||
} | ||
|
||
console.log(`Wallet ${signer.address} is now trying to buy another one from the public open edition...`) | ||
|
||
{ | ||
const mintTransaction = await clientSigner.edition.mint({ | ||
mintSchedule: openEditionDrop, | ||
quantity: 1, | ||
}) | ||
|
||
console.log('Mint transaction has been sent, waiting for completion...') | ||
|
||
const receipt = await mintTransaction.wait() | ||
|
||
const confirmedDate = fromUnixTime((await goerliProvider.getBlock(receipt.blockNumber)).timestamp) | ||
|
||
console.log( | ||
`Mint has been confirmed at ${confirmedDate}. Now wallet ${ | ||
signer.address | ||
} owns ${await clientSigner.edition.numberOfTokensOwned({ | ||
editionAddress: exampleEditionAddress, | ||
userAddress: signer.address, | ||
})}`, | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'dotenv/config' | ||
|
||
import { Wallet } from 'ethers' | ||
import { requireEnv } from 'require-env-variable' | ||
|
||
import { goerliProvider } from './alchemy' | ||
|
||
const { PUBLIC_WALLET_PRIVATE_KEY } = requireEnv('PUBLIC_WALLET_PRIVATE_KEY') | ||
|
||
export const signer = new Wallet(PUBLIC_WALLET_PRIVATE_KEY, goerliProvider) |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import assert from 'assert' | ||
|
||
import { clientMainnetProvider } from './clientMainnetProvider' | ||
|
||
const XYZ_EditionAddress = '0xA6c4df945DBB1D71Fe9a8D71Ae93B8d5C2BbeBE4' | ||
|
||
assert.strictEqual( | ||
await clientMainnetProvider.isSoundEdition({ | ||
editionAddress: XYZ_EditionAddress, | ||
}), | ||
true, | ||
) | ||
|
||
const XYZ_EditionInfo = clientMainnetProvider.edition.info({ | ||
contractAddress: XYZ_EditionAddress, | ||
}).contract | ||
|
||
console.log(await XYZ_EditionInfo.info) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, | ||
"module": "esnext" /* Specify what module code is generated. */, | ||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, | ||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, | ||
"moduleResolution": "node", | ||
"strict": true /* Enable all strict type-checking options. */, | ||
"noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */, | ||
"skipLibCheck": true /* Skip type checking all .d.ts files. */, | ||
"noEmit": true | ||
} | ||
} |
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.