Skip to content

This SDK enables you to interact with Tezos smart contracts of the Wrapped-XTZ project by StakerDAO.

License

Notifications You must be signed in to change notification settings

stove-labs/wrapped-xtz-sdk

Repository files navigation

npm version build Delphinet codecov Made with TypeScript styled with prettier License: MIT

Wrapped-XTZ SDK

This SDK for TypeScript and JavaScript enables you to interact with Tezos smart contracts of the Wrapped-XTZ project by StakerDAO.

Quickstart πŸͺ„

npm install @stove-labs/wxtz-sdk

Usage πŸ•Ή

Typescript

import { WXTZSDK, NetworkType } from '@stove-labs/wxtz-sdk';
import { InMemorySigner } from '@taquito/signer';
import { TezosToolkit } from '@taquito/taquito';

const Tezos = new TezosToolkit('https://testnet-tezos.giganode.io');
Tezos.setProvider({
  signer: new InMemorySigner(
    'edskSAVepaB1qJvJBrR9WK3X6JQneSGq2wf4jF4czWjMF3LyqtyELhGxqmx9gBADquKHr12uYpsDJA1H1RQJNBUUjkefytWs6e'
  ),
});

const wXTZConfig = {
  tezos: Tezos,
  network: NetworkType.delphinet,
  indexerUrl: 'https://you.better-call.dev',
};

(async function () {
  // initialize SDK
  const wXTZ = await WXTZSDK.at('KT1VMHXqjocCDZJ9cVwbtM1saLmXjyxwPb2h', wXTZConfig);
  // perform optional check
  const isValidContractCode = await wXTZ.checkContractCodeIntegrity();

  const createOvenContractMethod = await wXTZ.createOven('tz1QFeixME3pnRFwGFArJ5EFEc7uPjqxDNHY');
  const transactionOperation = await createOvenContractMethod.send();
  await transactionOperation.confirmation(1);

  // interact with oven
  const wXTZOven = await wXTZ.oven('KT1ovenAddress');
  await wXTZOven.initialize();
  // perform optional check
  const isValid = await wXTZOven.checkContractCodeIntegrity();

  // deposit
  const depositOperation = await (await wXTZOven.deposit()).send({
    amount: 100,
    mutez: true,
  });
  await depositOperation.confirmation(1);

  // withdraw
  const withdrawOperation = await (await wXTZOven.withdraw(100)).send();
  await withdrawOperation.confirmation(1);

  // set delegate
  const setDelegateOperation = await (await wXTZOven.setDelegate('tz1...')).send();
  await setDelegateOperation.confirmation(1);

  // remove delegate
  const removeDelegateOperation = await (await wXTZOven.setDelegate(null)).send();
  await removeDelegateOperation.confirmation(1);

  // get delegate
  const delegateAddress = await wXTZOven.getDelegate();

  // get core address
  const coreAddress = await wXTZOven.getCoreAddress();

  // get oven details for date/time of origination and last action, block height of origination
  const ovenDetails = await wXTZOven.getDetails();
})();

JavaScript

Example

const { WXTZSDK, NetworkType } = require('@stove-labs/wxtz-sdk');
const { InMemorySigner } = require('@taquito/signer');
const { TezosToolkit } = require('@taquito/taquito');

const Tezos = new TezosToolkit('https://testnet-tezos.giganode.io');
Tezos.setProvider({
  signer: new InMemorySigner(
    'edskSAVepaB1qJvJBrR9WK3X6JQneSGq2wf4jF4czWjMF3LyqtyELhGxqmx9gBADquKHr12uYpsDJA1H1RQJNBUUjkefytWs6e'
  ),
});

const wXTZConfig = {
  tezos: Tezos,
  network: NetworkType.delphinet,
  indexerUrl: 'https://you.better-call.dev',
};

(async function () {
  // initialize SDK
  const wXTZ = await WXTZSDK.at('KT1VMHXqjocCDZJ9cVwbtM1saLmXjyxwPb2h', wXTZConfig);
  // perform optional check
  const isValidContractCode = await wXTZ.checkContractCodeIntegrity();

  const createOvenContractMethod = await wXTZ.createOven('tz1QFeixME3pnRFwGFArJ5EFEc7uPjqxDNHY');
  const transactionOperation = await createOvenContractMethod.send();
  await transactionOperation.confirmation(1);

  // interact with oven
  const wXTZOven = await wXTZ.oven('KT1ovenAddress');
  await wXTZOven.initialize();
  // perform optional check
  const isValid = await wXTZOven.checkContractCodeIntegrity();

  // deposit
  const depositOperation = await (await wXTZOven.deposit()).send({
    amount: 100,
    mutez: true,
  });
  await depositOperation.confirmation(1);

  // withdraw
  const withdrawOperation = await (await wXTZOven.withdraw(100)).send();
  await withdrawOperation.confirmation(1);

  // set delegate
  const setDelegateOperation = await (await wXTZOven.setDelegate('tz1...')).send();
  await setDelegateOperation.confirmation(1);

  // remove delegate
  const removeDelegateOperation = await (await wXTZOven.setDelegate(null)).send();
  await removeDelegateOperation.confirmation(1);

  // get delegate
  const delegateAddress = await wXTZOven.getDelegate();

  // get core address
  const coreAddress = await wXTZOven.getCoreAddress();

  // get oven details for date/time of origination and last action, block height of origination
  const ovenDetails = await wXTZOven.getDetails();
})();

API Reference πŸ“š

Checkout the complete TypeDoc API reference.

Tests πŸ§ͺ

For running tests it is necessary to spin up a local Tezos sandbox node, migrating the test state and then executing the test runner. Make sure to have Docker running, node.js v12.x and jq installed.

npm run sandbox:start
npm run test:migrate
npm run test

License πŸ“ƒ

Wrapped-XTZ SDK is available under the MIT License.

Powered by


About

This SDK enables you to interact with Tezos smart contracts of the Wrapped-XTZ project by StakerDAO.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published