Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
@imtbl/core-sdk
Advanced tools
The Immutable Core SDK provides convenient access to Immutable's APIs and smart contracts to help projects build better web3 games and marketplaces.
Currently, our SDK supports interactions with our application-specific rollup based on StarkWare's StarkEx. In future, we'll be adding StarkNet support across our platform.
See our developer documentation for information on building on Immutable X.
See our API reference for more information on our APIs.
npm install @imtbl/core-sdk --save
# or
yarn add @imtbl/core-sdk
Initialize the Core SDK client with the network on which you want your application to run (see all networks available):
Param | Description |
---|---|
Config.SANDBOX | The default test network (currently, it is Goërli) |
Config.ROPSTEN | Ropsten test network (to be deprecated soon) |
Config.PRODUCTION | Ethereum network |
import { ImmutableX, Config } from '@imtbl/core-sdk';
const config = Config.SANDBOX; // Or PRODUCTION or ROPSTEN
const client = new ImmutableX(config);
These methods allow you to read data about events, transactions or current state on Immutable X (layer 2). They do not require any user authentication because no state is being changed.
Examples of the types of data that are typically retrieved include:
const listCollectionsResponse = await client.listCollections({
pageSize: 2,
});
const collection = listCollectionsResponse.result[0];
const collectionAssetsResponse = await client.listAssets({
collection: collection.address,
pageSize: 10,
});
There are two types of operations requiring user signatures:
In order to get user signatures, applications need to generate "signers".
A common transaction type is the transfer of asset ownership from one user to another (ie. asset sale). These operations require users to sign (approve) them to prove that they are valid.
These operations add to or update data in Immutable's databases and typically require the authorization of an object's owner (ie. a user creating a project on Immutable X).
Signers are abstractions of user accounts that can be used to sign transactions. A user's private key is required to generate them.
There are two ways to get signers in your application:
The first option, where an application obtains a user's private key directly, is risky because these keys allow anyone in possession of them full control of an account.
The second option provides an application with an interface to the user's account by prompting the user to connect with their wallet application (ie. mobile or browser wallet). Once connected the app can begin asking the user to sign transactions and messages without having to reveal their private key.
As Immutable X enables applications to execute signed transactions on both Ethereum (layer 1) and StarkEx (layer 2), signers are required for both these layers.
The Core SDK provides functionality for applications to generate Stark (L2) private keys and signers.
If you generate your own Stark private key, you will have to persist it. The key is randomly generated so cannot be deterministically re-generated.
import { AlchemyProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import { generateStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
// Create Ethereum signer
const ethNetwork = 'goerli'; // Or 'mainnet'
const provider = new AlchemyProvider(ethNetwork, YOUR_ALCHEMY_API_KEY);
const ethSigner = new Wallet(YOUR_PRIVATE_ETH_KEY).connect(provider);
// Create Stark signer
const starkPrivateKey = generateStarkPrivateKey(); // Or retrieve previously generated key
const starkSigner = createStarkSigner(starkPrivateKey);
The Wallet SDK Web provides connections to Metamask and WalletConnect browser wallets.
See this guide for how to set this up.
const createProjectResponse = await client.createProject(ethSigner, {
company_name: 'My Company',
contact_email: 'project@company.com',
name: 'Project name',
});
const projectId = createProjectResponse.id.toString();
const getProjectResponse = await client.getProject(ethSigner, projectId);
const depositResponse = await client.deposit(ethSigner, {
type: 'ETH',
amount: '500000000000000000', // Amount in wei
});
const signers = { ethSigner, starkSigner };
const orderResponse = await client.createOrder(signers, {
buy: {
type: 'ETH',
amount: '1230000000000000000', // Sale price in wei
},
sell: {
type: 'ERC721',
tokenAddress: '0x0fb969a08c7c39ba99c1628b59c0b7e5611bd396',
tokenId: '5',
},
});
Immutable X is built as a ZK-rollup in partnership with StarkWare. We chose the ZK-rollups because it is the only solution capable of scale without compromise. This means whenever you mint or trade an NFT on Immutable X, you pay zero gas, and the validity of all transactions are directly enforced by Ethereum’s security using zero-knowledge proofs -- the first “layer 2” for NFTs on Ethereum.
The Core SDK provides interfaces for all smart contracts required to interact with the Immutable X platform.
See all smart contracts available in the Core SDK.
import { Contracts, Config } from '@imtbl/core-sdk';
const config = Config.SANDBOX;
// Get instance of core contract
const contract = Contracts.Core.connect(
config.ethConfiguration.coreContractAddress,
ethSigner,
);
// Obtain necessary parameters...
// Populate and send transaction
const populatedTransaction = await contract.populateTransaction.depositNft(
starkPublicKey,
assetType,
vaultId,
tokenId,
);
const transactionResponse = await signer.sendTransaction(populatedTransaction);
The Immutable solidity contracts can be found under contracts
folder. Contract bindings in typescript is generated using hardhat.
The Core contract is Immutable's main interface with the Ethereum blockchain, based on StarkEx.
The Registration contract is a proxy smart contract for the Core contract that combines transactions related to onchain registration, deposits and withdrawals. When a user who is not registered onchain attempts to perform a deposit or a withdrawal, the Registration combines requests to the Core contract in order to register the user first. Users who are not registered onchain are not able to perform a deposit or withdrawal.
For example, instead of making subsequent transaction requests to the Core contract, i.e. registerUser
and depositNft
, a single transaction request can be made to the proxy Registration contract - registerAndWithdrawNft
.
Standard interface for interacting with ERC20 contracts, taken from OpenZeppelin.
Standard interface for interacting with ERC721 contracts, taken from OpenZeppelin.
# Install dependencies
yarn install
yarn build
# Run tests
yarn test
Check out how the Release process works
We use OpenAPI (formally known as Swagger) to auto-generate the API clients that connect to the public APIs. The OpenAPI spec is retrieved from https://api.x.immutable.com/openapi and also saved in the repo.
To re-generate the API client, run:
make generate-openapi-prod
This repository is using release-it to manage the CHANGELOG.md.
The following headings should be used as appropriate
This is an example with all the change headings. For actual usage, use only the one heading that is relevant. This goes at the top of the CHANGELOG.md above the most recent release.
...
## [Unreleased]
### Added
For new features.
### Changed
For changes in existing functionality.
### Deprecated
For soon-to-be removed features.
### Removed
For now removed features.
### Fixed
For any bug fixes.
...
The package.json
will contain the value of the previous release:
"version": "0.3.0",
yarn release
yes
to use changelog and package.json
no
yes
-alpha.x
or -beta.x
. The x
is the version for this particular release. For example, if the last published is 1.2.0
, use 1.2.1-alpha.1
or 1.3.0-alpha.1
depending on type of your changes.Immutable X is open to all to build on, with no approvals required. If you want to talk to us to learn more, or apply for developer grants, click below:
To get help from other developers, discuss ideas, and stay up-to-date on what's happening, become a part of our community on Discord.
You can also join the conversation, connect with other projects, and ask questions in our Immutable X Discourse forum.
You can also apply for marketing support for your project. Or, if you need help with an issue related to what you're building with Immutable X, click below to submit an issue. Select I have a question or issue related to building on Immutable X as your issue type.
Webpack 5 no longer uses NodeJS polyfills, such as crypto
, which in turn breaks the Core SDK resulting in errors such as
Module not found: Error: Can't resolve 'crypto'
.
To fix this, you can use a webpack polyfill plugin like node-polyfill-webpack-plugin, or if you're using create-react-app
in your project which hides the Webpack config, this blog post explains how to add polyfills to your CRA project.
[1.0.0-beta.3] - 2022-10-18
FAQs
Immutable Core SDK
The npm package @imtbl/core-sdk receives a total of 2,708 weekly downloads. As such, @imtbl/core-sdk popularity was classified as popular.
We found that @imtbl/core-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.