@jediswap/starknet-next
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

JavaScript library for StarkNet.

🕹️ Usage

Install starknet with npm

$ npm install starknet
# or
$ npm install starknet@next

Import starknet and use the API

The following code is used to build a simple AMM example from the cairo docs

import { defaultProvider, stark } from 'starknet';
const { getSelectorFromName } = stark;

const CONTRACT_ADDRESS =
  "0x03e19baa6cb2078631bcdb34844f3f7879449a544c9ce722681a54af08cff4b9";

/**
 * invokeFunction() example
**/

/** Reset the liquidity pool **/
const addTokenResponse = await defaultProvider.invokeFunction(
  {
    contractAddress: CONTRACT_ADDRESS,
    entrypoint: "init_pool",
    calldata: ["1000000", "1000000"],
  },
  abi // for displaying purposes only (default implementation has no display/ui)
);
console.log(addTokenResponse);

/**
 * callContract() example
**/

/** Get the balance of the liquidity pool of token A **/
const poolBalanceTokenA = await defaultProvider.callContract({
  contractAddress: CONTRACT_ADDRESS,
  entrypoint: "get_pool_token_balance",
  calldata: ["1"],
});
const balanceA = poolBalanceTokenA.result[0];
console.log('token a liquidity pool balance: ', parseInt(balanceA, 16));

/** Get the balance of the liquidity pool of token B **/
const poolBalanceTokenB = await defaultProvider.callContract({
  contractAddress: CONTRACT_ADDRESS,
  entrypoint: "get_pool_token_balance",
  calldata: ["2"],
});
const balanceB = poolBalanceTokenB.result[0];
console.log('token b liquidity pool balance: ', parseInt(balanceB, 16));

🌐 API

Click Here

🚀 Powered by Starknet.js

✏️ Contributing

If you consider to contribute to this project please read CONTRIBUTING.md first.

❤️ Special Thanks

Special thanks to all the contributors, especially to Janek (@janek26) from Argent for driving the development of Starknet.js.

This library would not be possible without these rockstars.

📜 License

Copyright (c) 2022 0xs34n

Licensed under the MIT license.

Package Sidebar

Install

npm i @jediswap/starknet-next

Weekly Downloads

0

Version

3.1.0

License

MIT

Unpacked Size

7.91 MB

Total Files

133

Last publish

Collaborators

  • retroboy
  • dhruvkelawala