Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
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));
If you consider to contribute to this project please read CONTRIBUTING.md first.
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.
Copyright (c) 2022 0xs34n
Licensed under the MIT license.
FAQs
JavaScript library for Starknet
The npm package starknet receives a total of 36,145 weekly downloads. As such, starknet popularity was classified as popular.
We found that starknet demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.