stellar-resource-usage
v1.0.13
Published
[![NPM version](https://img.shields.io/npm/v/stellar-resource-usage)](https://www.npmjs.com/package/stellar-resource-usage) [![View changelog](https://img.shields.io/badge/Explore%20Changelog-brightgreen)](https://github.com/57blocks/stellar-resource-usa
Downloads
978
Maintainers
Readme
stellar-resource-usage
Resource Limits
Example Report
Installation
npm
npm i stellar-resource-usage
pnpm
pnpm add stellar-resource-usage
bun
bun add stellar-resource-usage
Add the following to your contract:
import calcResource from "stellar-resource-usage"
Configuration:
interface CalcResourceProps {
tx: Transaction;
rpcServer: rpc.Server;
keypair: Keypair;
resourceFee?: number;
}
const params: CalcResourceProps = {
tx: tx,
rpcServer: rpc,
keypair: keypair,
}
calcResource(params)
Usage
Make sure Docker Desktop is running on your system
Start the unlimited network simulator. Executing the code below will launch a stellar/quickstart image. You can also customize your own image according to the quickstart if you want.
Note: Using npx requires you to install npm globally in advance, more info please refer to npx
npx dockerDev [--port=your port]
Make sure you have seen a steady stream of stellar-core: Synced! logs in step 2. Deploy your contract once your local network is running. If you don’t know how to deploy a contract, you can check the Stellar build doc or the deploy.example.ts we provide for reference.
Use the simulator in your code:
+ import calcResource from "stellar-resource-usage";
import {
Account,
Keypair,
Networks,
Operation,
rpc,
TransactionBuilder,
} from '@stellar/stellar-sdk';
// The port must be the same as dockerDev.
const rpcUrl = 'http://localhost:8000/rpc';
const rpcServer = new rpc.Server(rpcUrl, { allowHttp: true });
const keypair = Keypair.fromSecret('your secret key');
const pubkey = keypair.publicKey();
const contractId = 'your contract id';
// It must be STANDALONE.
const networkPassphrase = Networks.STANDALONE;
const source = await rpcServer
.getAccount(pubkey)
.then((account) => new Account(account.accountId(), account.sequenceNumber()))
.catch(() => {
throw new Error(
`Issue with ${pubkey} account. Ensure you're running dockerDev`
);
});
// your custom array.
const args = []
const tx = new TransactionBuilder(source, {
fee: '0',
networkPassphrase,
})
.addOperation(
Operation.invokeContractFunction({
contract: contractId,
function: 'your function in contract',
args,
})
)
.setTimeout(0)
.build();
+ calcResource({
+ tx,
+ rpcServer,
+ keypair,
+ })