{"id":20004500,"url":"https://github.com/kalepail/sorobill","last_synced_at":"2025-03-02T00:34:25.369Z","repository":{"id":218926101,"uuid":"707817807","full_name":"kalepail/sorobill","owner":"kalepail","description":"Estimate Soroban contract costs against all known limits","archived":false,"fork":false,"pushed_at":"2024-03-05T17:16:31.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-12T13:30:13.961Z","etag":null,"topics":["blockchain","cost","fees","simulation","soroban"],"latest_commit_sha":null,"homepage":"https://kalepail.com/blockchain/show-me-the-bill-part-2","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kalepail.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-20T18:18:38.000Z","updated_at":"2024-03-05T17:15:35.000Z","dependencies_parsed_at":"2024-11-13T09:16:50.750Z","dependency_job_id":null,"html_url":"https://github.com/kalepail/sorobill","commit_stats":null,"previous_names":["kalepail/sorobill"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kalepail%2Fsorobill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kalepail%2Fsorobill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kalepail%2Fsorobill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kalepail%2Fsorobill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kalepail","download_url":"https://codeload.github.com/kalepail/sorobill/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241444053,"owners_count":19963749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","cost","fees","simulation","soroban"],"created_at":"2024-11-13T05:30:29.028Z","updated_at":"2025-03-02T00:34:25.342Z","avatar_url":"https://github.com/kalepail.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sorobill\n[Relevant blog post](https://kalepail.com/blockchain/show-me-the-bill-part-2)\n\n## Step 1\nRun a `--limits unlimited` local network.\n```bash\ndocker run --rm -i \\\n    -p \"8000:8000\" \\\n    --name stellar \\\n    stellar/quickstart:pr579-latest \\\n    --local \\\n    --limits unlimited \\\n    --enable-soroban-rpc \\\n    --enable-soroban-diagnostic-events\n```\n\n## Step 2\nSimulate a transaction, optionally submit it, and pass forward the successful results to the `sorobill` method.\n\n### Without a TX\n```ts\nimport { Account, Keypair, Networks, Operation, SorobanRpc, TransactionBuilder, nativeToScVal, xdr } from \"@stellar/stellar-sdk\";\nimport { sorobill } from \"sorobill\";\n\nconst rpcUrl = 'http://localhost:8000/soroban/rpc'\nconst rpc = new SorobanRpc.Server(rpcUrl, { allowHttp: true })\n\nconst keypair = Keypair.fromSecret(ENV_SECRET)\nconst pubkey = keypair.publicKey()\n\nconst contractId = ENV_CONTRACT_ID\nconst networkPassphrase = Networks.STANDALONE\n\nconst args = [\n    nativeToScVal(1500, { type: 'u32' }),\n    nativeToScVal(200, { type: 'u32' }),\n    nativeToScVal(20, { type: 'u32' }),\n    nativeToScVal(40, { type: 'u32' }),\n    nativeToScVal(1, { type: 'u32' }),\n    nativeToScVal(Buffer.alloc(71_680)),\n]\n\nconst source = await rpc\n    .getAccount(pubkey)\n    .then((account) =\u003e new Account(account.accountId(), account.sequenceNumber()))\n\nconst simTx = new TransactionBuilder(source, {\n    fee: '0',\n    networkPassphrase\n})\n    .addOperation(Operation.invokeContractFunction({\n        contract: contractId,\n        function: 'run',\n        args\n    }))\n    .setTimeout(0)\n    .build()\n\nconst simRes = await rpc.simulateTransaction(simTx)\n\nif (SorobanRpc.Api.isSimulationSuccess(simRes))\n    console.log(sorobill(simRes));\n```\n```js\n{\n  cpu_insns: 122636493,\n  mem_bytes: 46670477,\n  entry_reads: 43,\n  entry_writes: 21,\n  read_bytes: 143508,\n  write_bytes: 68452,\n  events_and_return_bytes: 8272,\n  min_txn_bytes: undefined,\n  max_entry_bytes: undefined,\n  max_key_bytes: 352,\n}\n```\n\n### With a TX\n```ts\nimport { Account, Keypair, Networks, Operation, SorobanRpc, TransactionBuilder, nativeToScVal } from \"@stellar/stellar-sdk\";\nimport { sorobill } from \"sorobill\";\n\nconst rpcUrl = 'http://localhost:8000/soroban/rpc'\nconst rpc = new SorobanRpc.Server(rpcUrl, { allowHttp: true })\n\nconst keypair = Keypair.fromSecret(ENV_SECRET)\nconst pubkey = keypair.publicKey()\n\nconst contractId = ENV_CONTRACT_ID\nconst networkPassphrase = Networks.STANDALONE\n\nconst MAX_U32 = (2 ** 32) - 1\n\nconst args = [\n    nativeToScVal(1500, { type: 'u32' }),\n    nativeToScVal(200, { type: 'u32' }),\n    nativeToScVal(20, { type: 'u32' }),\n    nativeToScVal(40, { type: 'u32' }),\n    nativeToScVal(1, { type: 'u32' }),\n    nativeToScVal(Buffer.alloc(71_680)),\n]\n\nconst source = await rpc\n    .getAccount(pubkey)\n    .then((account) =\u003e new Account(account.accountId(), account.sequenceNumber()))\n\nconst simTx = new TransactionBuilder(source, {\n    fee: '0',\n    networkPassphrase\n})\n    .addOperation(Operation.invokeContractFunction({\n        contract: contractId,\n        function: 'run',\n        args\n    }))\n    .setTimeout(0)\n    .build()\n\nconst simRes = await rpc.simulateTransaction(simTx)\n\nif (SorobanRpc.Api.isSimulationSuccess(simRes)) {\n    simRes.minResourceFee = MAX_U32.toString()\n\n    const resources = simRes.transactionData.build().resources()\n    const tx = SorobanRpc.assembleTransaction(simTx, simRes)\n        .setSorobanData(simRes.transactionData\n            .setResourceFee(100_000_000)\n            .setResources(MAX_U32, resources.readBytes(), resources.writeBytes())\n            .build()\n        )\n        .build()\n\n    tx.sign(keypair)\n\n    const sendRes = await rpc.sendTransaction(tx)\n\n    if (sendRes.status === 'PENDING') {\n        await Bun.sleep(5000);\n        const getRes = await rpc.getTransaction(sendRes.hash)\n\n        if (getRes.status === 'SUCCESS')\n            console.log(await sorobill(simRes, getRes));\n    }\n}\n```\n```js\n{\n  cpu_insns: 130351778,\n  mem_bytes: 47448018,\n  entry_reads: 43,\n  entry_writes: 21,\n  read_bytes: 143508,\n  write_bytes: 68452,\n  events_and_return_bytes: 8272,\n  min_txn_bytes: 76132,\n  max_entry_bytes: 66920,\n  max_key_bytes: 352,\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkalepail%2Fsorobill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkalepail%2Fsorobill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkalepail%2Fsorobill/lists"}