npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coexyaedi/cyb-sdk

v1.0.4-rc1

Published

SDK for Choose Your Baker

Downloads

6

Readme

Choose Your Baker SDK v1.0.1

The SDK for Choose Your Baker. It enables issuers to issue Tezos transactions to a chosen baker.

Installation

Using npm:

npm install @coexyaedi/cyb-sdk

Configuration

SDK configuration

The constructor of CybAuth takes a Choose Your Baker Transaction Manager URL and an authentication token as parameters. The constructor of CybSdk takes a Tezos node URL as parameter.

import {CybSdk, CybAuth} from '@coexyaedi/cyb-sdk'

const auth = new CybAuth('https://TRANSACTION_MANAGER_URL', 'ISSUER_TOKEN')
const sdk: CybSdk = new CybSdk(auth, 'https://YOUR_PREFERRED_RPC_URL')

If the transaction manager is configured to accept unauthenticated submission of operations, the SDk can be used without a token.

import {CybSdk, CybAuth} from '@coexyaedi/cyb-sdk'

const auth = new CybAuth('https://TRANSACTION_MANAGER_URL')
const sdk: CybSdk = new CybSdk(auth, 'https://YOUR_PREFERRED_RPC_URL')

Tezos keys configuration

In order to sign operations, Tezos private key has to be provided to a signer.

import {InMemorySigner} from "@taquito/signer"

sdk.setProvider({
    signer: new InMemorySigner('SECRET_KEY')
})

Examples

Transfer some XTZ

It's mandatory to call the cybEstimate function before sending the request in order to get the right gas limit, storage limit, and the fees related to the transaction manager of the certified baker.

// Build a transaction to transfer 0.1 XTZ to destinationAddress
const params : ParamsWithKind[] = [
    {
        kind: OpKind.TRANSACTION,
        to: destinationAddress,
        amount: 0.1,
        fee: 0,
    }
]

 // Estimate for CYB
const estimateCyb = await sdk.cybEstimate(params)

// Send the operation
const response = await sdk.generateBatch(estimateCyb).send()

Transfer some XTZ and call a smart contract

// Smart Contract with on method: updateName
const simpleContract = await sdk.wallet.at('SMART_CONTRACT_ADDRESS')

const params : ParamsWithKind[] =[
    {
        kind: OpKind.TRANSACTION,
        to: destinationAddress,
        amount: 0.1,
        fee: 0,
    },
    {
        kind: OpKind.TRANSACTION,
        ...simpleContract.methods.updateName('MY_STRING').toTransferParams({})
    },
]

// Estimate for CYB
const estimateCyb = await sdk.cybEstimate(params)

// Send the operation
const response = await sdk.generateBatch(estimateCyb).send()

Specify a level

It is possible to specify at which level we want our operation to be baked (it has to be a baking slot of the chosen baker).

// Change context for next call
if (!sdk.isContextLocked) {
    sdk.modifyContext({
        level: WANTED_LEVEL,
    })
}

// Prepare and send operation
// ...
const response = await sdk.generateBatch(estimateCyb).send()
 
// Reset context for next call
if (!sdk.isContextLocked) {
    sdk.modifyContext({
        level: undefined,
    })
}

Get CYB information about an operation

// Send the operation
const response = await sdk.generateBatch(estimateCyb).send()

// Get operation
const operation = await sdk.operationService.getOperation({hash: response.opHash})

Delete an operation

It is possible to delete an operation from the mempool of CYB only if the operation has the PENDING status.

// Send the operation
const response = await sdk.generateBatch(estimateCyb).send()

// Delete the operation
const deletedOperation = await sdk.operationService.deleteOperation({hash: response.opHash})

You might want to verify the validity of the operation that was sent back.

// Verify the signature
const tzOperation = deletedOperation.tzOperation
const forgeParams: ForgeParams = {
    branch: tzOperation.branch,
    contents: tzOperation.contents,
}
const bytes = await sdk.cybRpc.forgeOperations(forgeParams)
const signature = await sdk.signer.sign(bytes, new Uint8Array([3]))

if (signature.prefixSig === tzOperation.signature) {
    console.log("Deleted operation is valid")
}

Update an operation

// Send the operation
const response = await sdk.generateBatch(estimateCyb).send()

// Delete and make a new batch from deleted operation
const deletedOperation = await sdk.operationService.deleteOperation({hash: response.opHash})
const batch = sdk.generateBatchFrom(deletedOperation)
batch.withTransfer({
    to: "tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6",
    amount: 1,
})

// Re-submit the operation
const secondOp = await batch.send()
const operation = await sdk.operationService.getOperation({hash: secondOp.opHash})