Socket
Socket
Sign inDemoInstall

starknet

Package Overview
Dependencies
Maintainers
1
Versions
220
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

starknet

JavaScript library for StarkNet


Version published
Weekly downloads
46K
increased by6.49%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 08 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc