{"_id":"@chainsatlas/atlas-sdk","_rev":"7-93a675c06aa3eff8231eec51f00b2ead","name":"@chainsatlas/atlas-sdk","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@chainsatlas/atlas-sdk","version":"0.1.0","keywords":["blockchain","web3","ethereum","evm","interoperability"],"author":{"name":"Marcos Medeiros","email":"marcos.medeiros@chainsatlas.com"},"license":"MIT","_id":"@chainsatlas/atlas-sdk@0.1.0","maintainers":[{"name":"marcos-medeiros","email":"marcos.medeiros@chainsatlas.com"}],"homepage":"https://github.com/ChainsAtlas/atlas-sdk#readme","bugs":{"url":"https://github.com/ChainsAtlas/atlas-sdk/issues"},"dist":{"shasum":"7606db4df1e53df1b96526fe1ed075a1dd299262","tarball":"https://registry.npmjs.org/@chainsatlas/atlas-sdk/-/atlas-sdk-0.1.0.tgz","fileCount":23,"integrity":"sha512-bavdjNYuZuZhJcqL9xkR9s4O3T0dpVyP6hU0bIRFifhT42mQyaHJvTbSF461zCHgAsTBJspo6JA+7Z59iluFxg==","signatures":[{"sig":"MEYCIQCrCuhS2ZpKVQqEkl2H4Sjb/C1sb+dzF4ZmMANAMYq+aQIhAL6UehIdm+5za9cpww9uREE7TrXGRBoC+z0/eK0bA/Kr","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":77655},"main":"dist/index.js","types":"./dist/index.d.ts","config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"gitHead":"4580144f66cb11dab5e3dcf3629e41122d936031","scripts":{"cm":"cz","test":"jest","build":"tsc","watch":"tsc --watch"},"_npmUser":{"name":"marcos-medeiros","email":"marcos.medeiros@chainsatlas.com"},"repository":{"url":"git+https://github.com/ChainsAtlas/atlas-sdk.git","type":"git"},"_npmVersion":"10.8.1","description":"Compile web2 code to run on web3 environments.","directories":{},"_nodeVersion":"22.4.1","dependencies":{"cross-fetch":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"9.x","globals":"^15.8.0","release":"^6.3.1","ts-node":"^10.9.2","prettier":"3.3.3","semantic":"^0.0.1","@eslint/js":"^9.7.0","commitizen":"^4.3.0","typescript":"^5.5.3","@commitlint/cli":"^19.3.0","semantic-release":"^24.0.0","typescript-eslint":"^7.16.1","@semantic-release/git":"^10.0.1","@semantic-release/npm":"^12.0.1","cz-conventional-changelog":"^3.3.0","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^19.2.2"},"_npmOperationalInternal":{"tmp":"tmp/atlas-sdk_0.1.0_1721331059555_0.043530398826181926","host":"s3://npm-registry-packages"}},"0.1.2":{"name":"@chainsatlas/atlas-sdk","version":"0.1.2","description":"Compile web2 code to run on web3 environments.","main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/ChainsAtlas/atlas-sdk.git"},"scripts":{"cm":"cz","build":"tsc","watch":"tsc --watch","prepublishOnly":"npm run build"},"keywords":["blockchain","web3","ethereum","evm","interoperability"],"author":{"name":"Marcos Medeiros","email":"marcos.medeiros@chainsatlas.com"},"license":"MIT","bugs":{"url":"https://github.com/ChainsAtlas/atlas-sdk/issues"},"homepage":"https://github.com/ChainsAtlas/atlas-sdk#readme","devDependencies":{"@commitlint/cli":"^19.3.0","@commitlint/config-conventional":"^19.2.2","@eslint/js":"^9.7.0","@semantic-release/changelog":"^6.0.3","@semantic-release/git":"^10.0.1","@semantic-release/npm":"^12.0.1","commitizen":"^4.3.0","cz-conventional-changelog":"^3.3.0","eslint":"9.x","globals":"^15.8.0","prettier":"3.3.3","release":"^6.3.1","semantic":"^0.0.1","semantic-release":"^24.0.0","ts-node":"^10.9.2","typescript":"^5.5.3","typescript-eslint":"^7.16.1"},"dependencies":{"cross-fetch":"^4.0.0"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"_id":"@chainsatlas/atlas-sdk@0.1.2","gitHead":"c26e7ae449c991a5421484ae1c04154f30151b58","types":"./dist/index.d.ts","_nodeVersion":"22.4.1","_npmVersion":"10.8.1","dist":{"integrity":"sha512-crA98fSyAql1UoPol2KZD1SrzoCgnNgkwsXT0DqxGegBd1wf2S9GnMuZdp13bFDDikcgJxLyz3GUslDgD1tnvQ==","shasum":"d89774e70dba138658da89e46f658f9de09a88f2","tarball":"https://registry.npmjs.org/@chainsatlas/atlas-sdk/-/atlas-sdk-0.1.2.tgz","fileCount":21,"unpackedSize":68141,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDX8xUKyD6U/ePV7ANHGDUvkVh/GqrFQz+xOTNuyvvBwAIhAOKPFiUdVOiHA/ynBwnrJ8tD6c2q7bLUAwfKtIGx3mgc"}]},"_npmUser":{"name":"marcos-medeiros","email":"marcos.medeiros@chainsatlas.com"},"directories":{},"maintainers":[{"name":"marcos-medeiros","email":"marcos.medeiros@chainsatlas.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/atlas-sdk_0.1.2_1721366588274_0.9394397343404348"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-18T19:30:59.409Z","modified":"2024-07-19T05:23:08.712Z","0.1.0":"2024-07-18T19:30:59.708Z","1.0.0":"2024-07-19T01:58:32.921Z","2.0.0":"2024-07-19T03:39:24.257Z","0.1.1":"2024-07-19T05:14:20.603Z","0.1.2":"2024-07-19T05:23:08.508Z"},"bugs":{"url":"https://github.com/ChainsAtlas/atlas-sdk/issues"},"author":{"name":"Marcos Medeiros","email":"marcos.medeiros@chainsatlas.com"},"license":"MIT","homepage":"https://github.com/ChainsAtlas/atlas-sdk#readme","keywords":["blockchain","web3","ethereum","evm","interoperability"],"repository":{"type":"git","url":"git+https://github.com/ChainsAtlas/atlas-sdk.git"},"description":"Compile web2 code to run on web3 environments.","maintainers":[{"name":"marcos-medeiros","email":"marcos.medeiros@chainsatlas.com"}],"readme":"# Atlas SDK\n## Any software in any programming language on any blockchain.\n\nThe Atlas SDK enables developers to execute traditional web2 languages like C, Javascript and Python on web3 environments. It works as a client to the ChainsAtlas API that compiles web2 code to bytecode compatible with the ChainsAtlas Virtualizatiom Unit.\n\nThe Virtualization Unit is a smart contract that contains a virtual machine capable of executing web2 code natively on blockchain. **Nothing is executed off-chain.** For more details, checkout the [ChainsAtlas Whitepaper](https://docsend.com/view/zgkukn7wsgimvf2w).\n\n## Getting started\n\n### Signup to get an API Key\nTo use the Atlas SDK, you will need an API Key. To generate it, you need to signup to the ChainsAtlas Dashboard at https://app.chainsatlas.com/signup\n\nOnce you signup, an API Key will be automatically generated and displayed to you at https://app.chainsatlas.com/dashboard.\n\n### Installation\n```\nnpm i @chainsatlas/atlas-sdk\n# or\npnpm i @chainsatlas/atlas-sdk\n# or\nyarn add @chainsatlas/atlas-sdk\n```\n\n### Usage\n\n#### Virtualization Unit Contract Deployment \n\nThe V_UNIT_ABI and V_UNIT_BYTECODE constants are used to deploy a new Virtualization Unit contract.\n\n```ts\n// ethers v6\nimport { ethers } from 'ethers'\nimport { V_UNIT_ABI, V_UNIT_BYTECODE } from '@chainsatlas/atlas-sdk'\n\nconst provider = new ethers.JsonRpcProvider('https://rpc.ankr.com/eth');\nconst wallet = new ethers.Wallet('0x...', provider);\nconst factory = new ethers.ContractFactory(\n    V_UNIT_ABI,\n    V_UNIT_BYTECODE,\n    wallet,\n);\nconst contract = await factory.deploy();\nawait contract.waitForDeployment();\nconst vUnitAddress = await contract.getAddress();\n\n// viem v2\nimport { createPublicClient, createWalletClient, http } from 'viem'\nimport { privateKeyToAccount } from 'viem/accounts'\nimport { mainnet } from 'viem/chains'\nimport { V_UNIT_ABI, V_UNIT_BYTECODE } from '@chainsatlas/atlas-sdk'\n\nconst account = privateKeyToAccount('0x...'); \nconst publicClient = createPublicClient({\nchain: mainnet,\ntransport: http('https://rpc.ankr.com/eth')\n});\nconst walletClient = createWalletClient({\n  account, \n  chain: mainnet,\n  transport: http('https://rpc.ankr.com/eth')\n});\nconst hash = await walletClient.deployContract({\n    abi: V_UNIT_ABI,\n    bytecode: V_UNIT_BYTECODE\n});\nconst receipt = await publicClient.waitForTransactionReceipt({ hash });\nconst vUnitAddress = receipt.contractAddress;\n\n// web3 v4\nimport { Web3 } from 'web3'\nimport { V_UNIT_ABI, V_UNIT_BYTECODE } from '@chainsatlas/atlas-sdk'\n\nconst web3 = new Web3('https://rpc.ankr.com/eth');\nconst account = web3.eth.accounts.privateKeyToAccount('0x...');\nconst contract = new web3.eth.Contract(V_UNIT_ABI);\nconst contractDeployer = contract.deploy({\n    data: \"0x\" + V_UNIT_BYTECODE,\n});\nconst gas = await contractDeployer.estimateGas({\n    from: account,\n});\nconst tx = await contractDeployer.send({\n    from: defaultAccount,\n    gas,\n    gasPrice: 10000000000,\n});\nconst vUnitAddress = tx.options.address;\n```\n\n#### Client\n\nAn HTTP client responsible to compile web2 code to bytecode compatible with the Virtualization Unit.\n\n```ts\nimport { Client } from '@chainsatlas/atlas-sdk'\n\nconst client = new Client(\"API KEY HERE\");\n\n// compile bytecode given the source code, file extension\n// and number of arguments of the main function.\nconst clientBytecode = await client.compile(sourceCode, \"c\", 2);\n\n// output: { bytecode: string; key: string; nargs: number; }\n```\n\n#### composeInput\n\nAn utility function responsible for adding dynamic inputs into the client bytecode returned by the ChainsAtlas API.\n\n```ts\nimport { composeInput } from '@chainsatlas/atlas-sdk'\n\n// compose input given the clientBytecode object\n// returned from 'client.compile()' and arg values\n// IMPORTANT: args array must have length equal to clientBytecode.nargs\nconst bytecodeInput = composeInput(clientBytecode, [42, 73]);\n\n// output: string\n```\n\n#### Running bytecode on the Virtualization Unit\n\nTo run code on the Virtualization Unit, you must first compile the source code to bytecode compatible with the Virtualization Unit using `Client.compile()` and then add the necessary inputs with the `composeInput` utility function.\n\n```ts\n// ethers v6\nimport { ethers } from 'ethers'\nimport { V_UNIT_ABI } from '@chainsatlas/atlas-sdk'\n\nconst provider = new ethers.JsonRpcProvider('https://rpc.ankr.com/eth');\nconst wallet = new ethers.Wallet('0x...', provider);\nconst contract = new ethers.Contract(contractAddress, V_UNIT_ABI, wallet);\nconst txResponse = await contract.runBytecode(bytecodeInput);\nconst receipt = await txResponse.wait();\n\n// viem v2\nimport { createPublicClient, createWalletClient, http, getContract } from 'viem'\nimport { privateKeyToAccount } from 'viem/accounts'\nimport { mainnet } from 'viem/chains'\nimport { V_UNIT_ABI } from '@chainsatlas/atlas-sdk'\n\nconst account = privateKeyToAccount('0x...'); \nconst publicClient = createPublicClient({\nchain: mainnet,\ntransport: http('https://rpc.ankr.com/eth')\n});\nconst walletClient = createWalletClient({\n  account, \n  chain: mainnet,\n  transport: http('https://rpc.ankr.com/eth')\n});\nconst contract = getContract({\n    address: vUnitAddress,\n    abi: V_UNIT_ABI,\n    client: { public: publicClient, wallet: walletClient }\n});\nconst hash = await contract.write.runBytecode(bytecodeInput);\nconst receipt = await publicClient.waitForTransactionReceipt({ hash });\n\n// web3 v4\nimport { Web3 } from 'web3'\nimport { V_UNIT_ABI, V_UNIT_BYTECODE } from '@chainsatlas/atlas-sdk'\n\nconst web3 = new Web3('https://rpc.ankr.com/eth');\nconst account = web3.eth.accounts.privateKeyToAccount('0x...');\nconst contract = new web3.eth.Contract(V_UNIT_ABI, vUnitAddress);\nconst receipt = await contract.methods.runBytecode(bytecodeInput)\n    .send({\n        from: account,\n        gas: 1000000, // adjust as needed\n        gasPrice: \"10000000000\"\n    });\n```\n\n#### Getting Bytecode Return\n\nIf your bytecode returns a value upon execution, you can get the runtime return in hex format given a Virtualization Unit Contract Instance and the receipt of the `runBytecode` transaction.\n\n```ts\n// ethers v6\nconst eventFilter = contract.filters.ContractDeployed();\nconst eventTopicArray = await eventFilter.getTopicFilter();\nconst logs = receipt.logs.filter((log) =>\n    log.topics.includes(eventTopicArray[0]),\n);\nconst decodedLogs = logs.map((log) =>\n    contract.interface.parseLog(log),\n);\nconst bytecodeAddress = decodedLogs[0].args.bytecodeAddress;\nconst bytecodeOutput = await contract.getRuntimeReturn(bytecodeAddress);\n```\n\n## Supported Chains Status\n\n| Chain      | Status      |\n|------------|-------------|\n| EVM chains | Supported   |\n| AElf       | Supported   |\n| Stellar    | In progress |\n\n## Supported languages\n\n| Language   | Status      |\n|------------|-------------|\n| C          | Supported   |\n| Solidity   | In progress |\n| JavaScript | Coming soon |\n| Python     | Coming soon |\n\n**IMPORTANT:** Make sure to use currently supported language features to avoid any errors. The ChainsAtlas' team is always working towards more features, so it is important to stay updated about latest developments. By [signing up to our dashboard](https://app.chainsatlas.com/signup), you will receive an email everytime we ship a new features. For more information, [see our docs on available language features](https://docs.chainsatlas.com/).\n\n## Troubleshooting\n\nIf you encounter issues:\n\n- Check the error message for guidance.\n- Ensure API Key is correct.\n- Ensure you are using a stable RPC.\n- Contact us at info@chainsatlas.com\n\n## Contributing\n\nWe welcome contributions! If you have suggestions, bug reports, or feature requests, please [open an issue on our GitHub repository](https://github.com/ChainsAtlas/atlas-sdk/issues).\n","readmeFilename":"README.md"}