Skip to content

Commit

Permalink
Updating README.md (#157)
Browse files Browse the repository at this point in the history
* Updating README.md

* Removing export keyword
  • Loading branch information
EvgenKor authored Jul 21, 2023
1 parent 9659494 commit ea7ad3e
Showing 1 changed file with 44 additions and 40 deletions.
84 changes: 44 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,65 @@

## Example

The following code was checked with the client library `v5.2.0`

```typescript
import { ZkBobClient, ClientConfig, AccountConfig,
ProverMode, TransferRequest, deriveSpendingKeyZkBob
} from 'zkbob-client-js';
ProverMode, TransferRequest, deriveSpendingKeyZkBob, DepositType, TxType
} from 'zkbob-client-js';


async function zkBobExample(): Promise<void> {
// Client configuration includes set of pools, chains, parameters and other options
const clientConfig: ClientConfig = {
pools: {
'BOB-sepolia': {
'chainId': 11155111,
'poolAddress': '0x3bd088C19960A8B5d72E4e01847791BD0DD1C9E6',
'tokenAddress': '0x2C74B18e2f84B78ac67428d0c7a9898515f0c46f',
'relayerUrls': ['https://relayer.thgkjlr.website/'],
// external service to speed-up proof calculation, optional
'delegatedProverUrls': [],
// file with archived pool state
// (optional, needed to reduce sync time)
'coldStorageConfigPath': ''
}
},
chains: {
'11155111': {
rpcUrls: ['https://rpc.sepolia.org'] // list of available JSON RPC endpoints
},
},
snarkParams: {
transferParamsUrl: '/path/to/transfer/params',
transferVkUrl: '/path/to/transfer/vk'
},
supportId: 'unique_string_generated_with_uuidv4',
forcedMultithreading: undefined // multithreading config will be selected automatically
pools: {
'BOB-sepolia': {
'chainId': 11155111,
'poolAddress': '0x3bd088C19960A8B5d72E4e01847791BD0DD1C9E6',
'tokenAddress': '0x2C74B18e2f84B78ac67428d0c7a9898515f0c46f',
'relayerUrls': ['https://relayer.thgkjlr.website/'],
// external service to speed-up proof calculation, optional
'delegatedProverUrls': [],
// file with archived pool state
// (optional, needed to reduce sync time)
'coldStorageConfigPath': '',
// deposit scheme depends on token
'depositScheme': DepositType.SaltedPermit
}
},
chains: {
'11155111': {
rpcUrls: ['https://rpc.sepolia.org'] // list of available JSON RPC endpoints
},
},
snarkParams: {
transferParamsUrl: "./assets/transfer_params.bin",
transferVkUrl: "./assets/transfer_verification_key.json"
},
supportId: 'unique_string_generated_with_uuidv4',
forcedMultithreading: undefined // multithreading config will be selected automatically
};

// creating a zkBob client without account to be worked on 'BOB-sepolia' pool
const client = await ZkBobClient.create(clientConfig, 'BOB-sepolia');

// now you can get relayer fee or pool limits for example
const relayerFee = await client.atomicTxFee();
console.log(`Relayer default fee: ${relayerFee} Gwei`);
const depositFee = await client.atomicTxFee(TxType.BridgeDeposit);
console.log(`Relayer deposit fee: ${depositFee} Gwei`);
console.log(`Pool deposit total limit: ${(await client.getLimits(undefined)).deposit.total} Gwei`);

// now let's attach account generated from the arbitrary 12-words mnemonic:
const mnemonic = 'magic trophy foil direct marriage glad bench wash doctor risk end cheap';
const accountConfig: AccountConfig = {
// spending key is a byte array which derived from mnemonic
sk: deriveSpendingKeyZkBob(mnemonic),
// pool alias which should be activated
pool: 'BOB-sepolia',
// the account should have no activity (incoming notes including) before that index
// you can use -1 value only for newly created account or undefined (or 0) for full state sync
birthindex: 0,
// using local prover
proverMode: ProverMode.Local,
// spending key is a byte array which derived from mnemonic
sk: deriveSpendingKeyZkBob(mnemonic),
// pool alias which should be activated
pool: 'BOB-sepolia',
// the account should have no activity (incoming notes including) before that index
// you can use -1 value only for newly created account or undefined (or 0) for full state sync
birthindex: 0,
// using local prover
proverMode: ProverMode.Local,
};
await client.login(accountConfig);

Expand All @@ -69,12 +73,12 @@ async function zkBobExample(): Promise<void> {

// and now let's transfer a few tokens inside the pool
const tx: TransferRequest = {
destination: 'zkbob_sepolia:HGkddpMXSfbXPEa8hUcttUaXpSPJihwA75q2Gue8QGxZtyDieqzb3iSRecdxS7d', // shielded address
amountGwei: BigInt('5000000000'), // 5 BOB
destination: 'zkbob_sepolia:HGkddpMXSfbXPEa8hUcttUaXpSPJihwA75q2Gue8QGxZtyDieqzb3iSRecdxS7d', // shielded address
amountGwei: BigInt('5000000000'), // 5 BOB
}
// returns an array of job ID for every transaction
// (single transfer may produce several transactions to the pool)
const jobIds = await client.transferMulti([tx], relayerFee);
const jobIds = await client.transferMulti([tx]);
// wait while all transactions will be processed by relayer
const result = await client.waitJobsTxHashes(jobIds);
console.log(`${result.map((t) => `job #${t.jobId}: ${t.txHash}]`).join(`\n`)}`);
Expand Down

0 comments on commit ea7ad3e

Please sign in to comment.