### Get Total Supply Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to retrieve the total supply of JPYC tokens on the local network using the JPYC V1 SDK. ```shell yarn run total-supply ``` -------------------------------- ### Mint JPYC Tokens Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to mint new JPYC tokens on the local network using the JPYC V1 SDK. ```shell yarn run mint ``` -------------------------------- ### Run Local Hardhat Network with Yarn Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md Starts a local Hardhat network and its accompanying node. This provides a local blockchain environment for testing contract deployments and interactions. ```shell yarn run node ``` -------------------------------- ### Transfer JPYC Tokens Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to transfer JPYC tokens between accounts on the local network using the JPYC V1 SDK. ```shell yarn run transfer ``` -------------------------------- ### Receive with Authorization (EIP3009) Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to receive JPYC tokens using signatures as defined by EIP3009, utilizing the JPYC V1 SDK. ```shell yarn run receive-with-authorization ``` -------------------------------- ### Transfer From Spender Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to transfer JPYC tokens from a spender's allowance using the JPYC V1 SDK. ```shell yarn run transfer-from ``` -------------------------------- ### Initialize JPYC SDK Client and Wallets Source: https://context7.com/jcam1/sdk-examples/llms.txt Initializes the JPYC SDK client with network configuration and generates wallet accounts for transaction signing. It utilizes environment variables for network details and depends on '@jpyc/sdk-core' and '@jpyc/sdk-v1'. ```typescript import { ChainName, Endpoint, NetworkName } from '@jpyc/sdk-core'; import { IJPYC, ISdkClient, JPYC, SdkClient } from '@jpyc/sdk-v1'; // Initialize SDK client const sdkClient: ISdkClient = new SdkClient({ chainName: process.env.CHAIN_NAME as ChainName, networkName: process.env.NETWORK_NAME as NetworkName, rpcEndpoint: process.env.RPC_ENDPOINT as Endpoint, }); // Generate accounts const account = sdkClient.createPrivateKeyAccount({}); const receiver = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8'; // Create local clients const client = sdkClient.createLocalClient({ account: account, }); // Initialize JPYC SDK instance const jpyc: IJPYC = new JPYC({ client: client, }); ``` -------------------------------- ### Permit Allowance (EIP2612) Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to permit an allowance using EIP2612 signature, allowing spending without a traditional `approve` call, using the JPYC V1 SDK. ```shell yarn run permit ``` -------------------------------- ### Transfer with Authorization (EIP3009) Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to transfer JPYC tokens using signatures as defined by EIP3009, utilizing the JPYC V1 SDK. ```shell yarn run transfer-with-authorization ``` -------------------------------- ### Build Packages with Yarn Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md Compiles and builds the necessary packages for the JPYC V1 SDK. This is a prerequisite step before running other commands. ```shell yarn run compile ``` -------------------------------- ### Cancel Authorization (EIP3009) Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to cancel a pending token authorization using EIP3009, utilizing the JPYC V1 SDK. ```shell yarn run cancel-authorization ``` -------------------------------- ### Approve Allowance Example Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md An example command to demonstrate how to approve an allowance for another address to spend JPYC tokens on behalf of the caller, using the JPYC V1 SDK. ```shell yarn run approve ``` -------------------------------- ### Generate Environment File with Yarn Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md Generates the `.env` file required for configuring the local development environment. This command automates the creation of environment-specific settings. ```shell yarn run env ``` -------------------------------- ### Approve Token Allowance with EIP-2612 Signature (TypeScript) Source: https://context7.com/jcam1/sdk-examples/llms.txt This example demonstrates how to approve a token allowance using EIP-2612 (Permit) by signing a transaction off-chain. It prepares EIP-712 typed data, signs it using the provided client and account, and then executes the permit on-chain. Finally, it verifies the updated allowance. Dependencies include 'soltypes', 'viem', and '@jpyc/sdk-core'. ```typescript import { Uint8, Uint256 } from 'soltypes'; import { hexToNumber, slice } from 'viem'; import { LOCAL_PROXY_ADDRESS, SUPPORTED_CHAINS } from '@jpyc/sdk-core'; import { account, client, jpyc, spender } from './'; async function main(): Promise { // Prepare EIP-712 typed data const domain = { name: 'JPY Coin', version: '1', chainId: BigInt(SUPPORTED_CHAINS.local.mainnet.id), verifyingContract: LOCAL_PROXY_ADDRESS, } as const; const types = { EIP712Domain: [ { name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' }, ], Permit: [ { name: 'owner', type: 'address' }, { name: 'spender', type: 'address' }, { name: 'value', type: 'uint256' }, { name: 'nonce', type: 'uint256' }, { name: 'deadline', type: 'uint256' }, ], } as const; const value = 300n; const deadline = BigInt(Date.now()) / 1000n + 3600n; const nonce = await jpyc.nonces({ owner: account.address }); // Sign typed data const signature = await client.signTypedData({ account, domain, types, primaryType: 'Permit', message: { owner: account.address, spender: spender, value: value, nonce: BigInt(nonce.toString()), deadline: deadline, }, }); const v = slice(signature, 64, 65); const r = slice(signature, 0, 32); const s = slice(signature, 32, 64); // Execute permit await jpyc.permit({ owner: account.address, spender: spender, value: Uint256.from(value.toString()), deadline: Uint256.from(deadline.toString()), v: Uint8.from(hexToNumber(v).toString()), r: r, s: s, }); // Verify allowance const allowance = await jpyc.allowance({ owner: account.address, spender: spender, }); console.log(`spender allowance: ${allowance.toString()}`); // Output: spender allowance: 300 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Transfer Tokens Using Pre-approved Allowance (TypeScript) Source: https://context7.com/jcam1/sdk-examples/llms.txt This example demonstrates how to transfer JPYC tokens from an owner's address to a receiver's address using a previously approved allowance. It utilizes the `transferFrom` method of the JPYC contract. Dependencies include 'soltypes'. The function logs the sender's, spender's, and receiver's balances after the transfer. ```typescript import { Uint256 } from 'soltypes'; import { account, jpyc, jpycSpender, receiver, spender } from './'; async function main(): Promise { // Transfer from approved address await jpycSpender.transferFrom({ from: account.address, to: receiver, value: Uint256.from('200'), }); // Check balances const balanceSender = await jpyc.balanceOf({ account: account.address, }); console.log(`balance (sender): ${balanceSender.toString()}`); // Output: balance (sender): 9700 const balanceSpender = await jpyc.balanceOf({ account: spender, }); console.log(`balance (spender): ${balanceSpender.toString()}`); // Output: balance (spender): 0 const balanceReceiver = await jpyc.balanceOf({ account: receiver, }); console.log(`balance (receiver): ${balanceReceiver.toString()}`); // Output: balance (receiver): 300 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### TypeScript: Receive With Authorization (EIP-3009) using viem and @jpyc/sdk-core Source: https://context7.com/jcam1/sdk-examples/llms.txt This TypeScript snippet demonstrates how to allow a receiver to pull tokens from a sender using a cryptographic signature, as per EIP-3009. It utilizes the 'viem' library for signing and '@jpyc/sdk-core' for contract interactions. The process involves preparing EIP-712 typed data, signing it, and then executing the receive transaction. It verifies sender and receiver balances post-transaction. Dependencies include 'crypto', 'soltypes', 'viem', and '@jpyc/sdk-core'. ```typescript import { randomBytes } from 'crypto'; import { Uint8, Uint256 } from 'soltypes'; import { hexToNumber, slice, toHex } from 'viem'; import { LOCAL_PROXY_ADDRESS, SUPPORTED_CHAINS } from '@jpyc/sdk-core'; import { account, client, jpyc, jpycReceiver, receiver } from './'; async function main(): Promise { // Prepare EIP-712 typed data const domain = { name: 'JPY Coin', version: '1', chainId: BigInt(SUPPORTED_CHAINS.local.mainnet.id), verifyingContract: LOCAL_PROXY_ADDRESS, } as const; const types = { EIP712Domain: [ { name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' }, ], ReceiveWithAuthorization: [ { name: 'from', type: 'address' }, { name: 'to', type: 'address' }, { name: 'value', type: 'uint256' }, { name: 'validAfter', type: 'uint256' }, { name: 'validBefore', type: 'uint256' }, { name: 'nonce', type: 'bytes32' }, ], } as const; const value = 100n; const validAfter = 0n; const validBefore = BigInt(Date.now()) / 1000n + 3600n; const nonce = toHex(randomBytes(32)); // Sign receive authorization const signature = await client.signTypedData({ account, domain, types, primaryType: 'ReceiveWithAuthorization', message: { from: account.address, to: receiver, value: value, validAfter: validAfter, validBefore: validBefore, nonce: nonce, }, }); const v = slice(signature, 64, 65); const r = slice(signature, 0, 32); const s = slice(signature, 32, 64); // Execute receive with signature await jpycReceiver.receiveWithAuthorization({ from: account.address, to: receiver, value: Uint256.from(value.toString()), validAfter: Uint256.from(validAfter.toString()), validBefore: Uint256.from(validBefore.toString()), nonce: nonce, v: Uint8.from(hexToNumber(v).toString()), r: r, s: s, }); // Verify balances const balanceSender = await jpyc.balanceOf({ account: account.address, }); console.log(`balance (sender): ${balanceSender.toString()}`); // Output: balance (sender): 9500 const balanceReceiver = await jpyc.balanceOf({ account: receiver, }); console.log(`balance (receiver): ${balanceReceiver.toString()}`); // Output: balance (receiver): 500 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Check JPYC Total Supply Source: https://context7.com/jcam1/sdk-examples/llms.txt Queries and logs the total supply of JPYC tokens currently in circulation. This function relies on the initialized 'jpyc' object and outputs the total supply as a string. ```typescript import { jpyc } from './'; async function main(): Promise { const totalSupply = await jpyc.totalSupply(); console.log(`totalSupply: ${totalSupply.toString()}`); // Output: totalSupply: 10000 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Mint JPYC Tokens Source: https://context7.com/jcam1/sdk-examples/llms.txt Configures a minter address with an allowance and mints new JPYC tokens to a specified address. It requires the 'soltypes' library for Uint256 and uses the initialized 'jpyc' and 'account' objects. Outputs the minter allowance and the new total supply. ```typescript import { Uint256 } from 'soltypes'; import { jpyc, account } from './'; async function main(): Promise { // Configure a minter with allowance await jpyc.configureMinter({ minter: account.address, minterAllowedAmount: Uint256.from('1000000'), }); // Check minter allowance const minterAllowance = await jpyc.minterAllowance({ minter: account.address }); console.log(`minterAllowance: ${minterAllowance.toString()}`); // Output: minterAllowance: 1000000 // Mint tokens await jpyc.mint({ to: account.address, amount: Uint256.from('10000'), }); // Check total supply const totalSupply = await jpyc.totalSupply(); console.log(`new totalSupply: ${totalSupply.toString()}`); // Output: new totalSupply: 10000 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Deploy JPYCv2 Contracts with Yarn Source: https://github.com/jcam1/sdk-examples/blob/main/packages/v1/README.md Deploys the JPYCv2 contracts to the local Hardhat network. After successful deployment, it creates a file containing the addresses of the deployed contracts, which should be updated in the `.env` file. ```shell yarn run deploy ``` -------------------------------- ### Execute Token Transfers with Signatures (TypeScript) Source: https://context7.com/jcam1/sdk-examples/llms.txt This TypeScript code snippet demonstrates how to prepare EIP-712 typed data for a token transfer, sign it using a client, and then execute the transfer with the generated signature. It requires the 'crypto', 'soltypes', 'viem', and '@jpyc/sdk-core' libraries. The function prepares domain and type definitions, sets transfer parameters, signs the message, extracts signature components (v, r, s), and finally calls the 'transferWithAuthorization' method to perform the transfer. It concludes by verifying the sender and receiver balances. ```typescript import { randomBytes } from 'crypto'; import { Uint8, Uint256 } from 'soltypes'; import { hexToNumber, slice, toHex } from 'viem'; import { LOCAL_PROXY_ADDRESS, SUPPORTED_CHAINS } from '@jpyc/sdk-core'; import { account, client, jpyc, jpycSpender, receiver, spender } from './'; async function main(): Promise { // Prepare EIP-712 typed data const domain = { name: 'JPY Coin', version: '1', chainId: BigInt(SUPPORTED_CHAINS.local.mainnet.id), verifyingContract: LOCAL_PROXY_ADDRESS, } as const; const types = { EIP712Domain: [ { name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' }, ], TransferWithAuthorization: [ { name: 'from', type: 'address' }, { name: 'to', type: 'address' }, { name: 'value', type: 'uint256' }, { name: 'validAfter', type: 'uint256' }, { name: 'validBefore', type: 'uint256' }, { name: 'nonce', type: 'bytes32' }, ], } as const; const value = 100n; const validAfter = 0n; const validBefore = BigInt(Date.now()) / 1000n + 3600n; const nonce = toHex(randomBytes(32)); // Sign transfer authorization const signature = await client.signTypedData({ account, domain, types, primaryType: 'TransferWithAuthorization', message: { from: account.address, to: receiver, value: value, validAfter: validAfter, validBefore: validBefore, nonce: nonce, }, }); const v = slice(signature, 64, 65); const r = slice(signature, 0, 32); const s = slice(signature, 32, 64); // Execute transfer with signature await jpycSpender.transferWithAuthorization({ from: account.address, to: receiver, value: Uint256.from(value.toString()), validAfter: Uint256.from(validAfter.toString()), validBefore: Uint256.from(validBefore.toString()), nonce: nonce, v: Uint8.from(hexToNumber(v).toString()), r: r, s: s, }); // Verify balances const balanceSender = await jpyc.balanceOf({ account: account.address, }); console.log(`balance (sender): ${balanceSender.toString()}`); // Output: balance (sender): 9600 const balanceReceiver = await jpyc.balanceOf({ account: receiver, }); console.log(`balance (receiver): ${balanceReceiver.toString()}`); // Output: balance (receiver): 400 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Approve JPYC Token Allowance Source: https://context7.com/jcam1/sdk-examples/llms.txt Approves a spender address to withdraw tokens from the owner's account up to a specified amount. It then verifies the approved allowance. Requires 'soltypes' for Uint256 and uses 'jpyc', 'account', and 'spender' variables. ```typescript import { Uint256 } from 'soltypes'; import { account, jpyc, spender } from './'; async function main(): Promise { // Approve spender await jpyc.approve({ spender: spender, value: Uint256.from('1000'), }); // Check allowance const allowance = await jpyc.allowance({ owner: account.address, spender: spender, }); console.log(`spender allowance: ${allowance.toString()}`); // Output: spender allowance: 1000 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Transfer JPYC Tokens Source: https://context7.com/jcam1/sdk-examples/llms.txt Transfers a specified amount of JPYC tokens from the sender's address to a receiver's address. It verifies the transaction by checking the sender's and receiver's balances afterwards. Requires 'soltypes' for Uint256 and uses 'jpyc', 'account', and 'receiver' variables. ```typescript import { Uint256 } from 'soltypes'; import { account, jpyc, receiver } from './'; async function main(): Promise { // Transfer tokens await jpyc.transfer({ to: receiver, value: Uint256.from('100'), }); // Check sender balance const balanceSender = await jpyc.balanceOf({ account: account.address, }); console.log(`balance (sender): ${balanceSender.toString()}`); // Output: balance (sender): 9900 // Check receiver balance const balanceReceiver = await jpyc.balanceOf({ account: receiver, }); console.log(`balance (receiver): ${balanceReceiver.toString()}`); // Output: balance (receiver): 100 } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` -------------------------------- ### Cancel JPYC Authorization (EIP-3009) with TypeScript Source: https://context7.com/jcam1/sdk-examples/llms.txt This TypeScript code snippet demonstrates how to cancel a previously signed JPYC token transfer authorization using the EIP-3009 standard. It requires importing necessary modules from the '@jpyc/sdk-core' and 'viem' libraries. The function signs both the original transfer and the cancellation, executes the cancellation, and then attempts to use the original authorization to prove it has been cancelled. ```typescript import { randomBytes } from 'crypto'; import { Uint8, Uint256 } from 'soltypes'; import { hexToNumber, slice, toHex } from 'viem'; import { LOCAL_PROXY_ADDRESS, SUPPORTED_CHAINS } from '@jpyc/sdk-core'; import { account, client, jpyc, jpycSpender, receiver } from './'; async function main(): Promise { const domain = { name: 'JPY Coin', version: '1', chainId: BigInt(SUPPORTED_CHAINS.local.mainnet.id), verifyingContract: LOCAL_PROXY_ADDRESS, } as const; const value = 100n; const validAfter = 0n; const validBefore = BigInt(Date.now()) / 1000n + 3600n; const nonce = toHex(randomBytes(32)); // Sign transfer authorization const signatureTransfer = await client.signTypedData({ account, domain, types: { EIP712Domain: [ { name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' }, ], TransferWithAuthorization: [ { name: 'from', type: 'address' }, { name: 'to', type: 'address' }, { name: 'value', type: 'uint256' }, { name: 'validAfter', type: 'uint256' }, { name: 'validBefore', type: 'uint256' }, { name: 'nonce', type: 'bytes32' }, ], }, primaryType: 'TransferWithAuthorization', message: { from: account.address, to: receiver, value: value, validAfter: validAfter, validBefore: validBefore, nonce: nonce, }, }); const vTransfer = slice(signatureTransfer, 64, 65); const rTransfer = slice(signatureTransfer, 0, 32); const sTransfer = slice(signatureTransfer, 32, 64); // Sign cancellation authorization const signatureCancellation = await client.signTypedData({ account, domain, types: { EIP712Domain: [ { name: 'name', type: 'string' }, { name: 'version', type: 'string' }, { name: 'chainId', type: 'uint256' }, { name: 'verifyingContract', type: 'address' }, ], CancelAuthorization: [ { name: 'authorizer', type: 'address' }, { name: 'nonce', type: 'bytes32' }, ], }, primaryType: 'CancelAuthorization', message: { authorizer: account.address, nonce: nonce, }, }); const vCancellation = slice(signatureCancellation, 64, 65); const rCancellation = slice(signatureCancellation, 0, 32); const sCancellation = slice(signatureCancellation, 32, 64); // Execute cancellation await jpyc.cancelAuthorization({ authorizer: account.address, nonce: nonce, v: Uint8.from(hexToNumber(vCancellation).toString()), r: rCancellation, s: sCancellation, }); // Attempt to use cancelled authorization try { await jpycSpender.transferWithAuthorization({ from: account.address, to: receiver, value: Uint256.from(value.toString()), validAfter: Uint256.from(validAfter.toString()), validBefore: Uint256.from(validBefore.toString()), nonce: nonce, v: Uint8.from(hexToNumber(vTransfer).toString()), r: rTransfer, s: sTransfer, }); } catch (error) { console.log(`Meta-transaction has been cancelled.\n\n${error}`); // Output: Meta-transaction has been cancelled. } } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.