{"id":28172999,"url":"https://github.com/archethic-foundation/libjs","last_synced_at":"2025-05-15T20:12:15.615Z","repository":{"id":37741513,"uuid":"276306790","full_name":"archethic-foundation/libjs","owner":"archethic-foundation","description":"Archethic Javascript SDK","archived":false,"fork":false,"pushed_at":"2025-04-17T13:47:56.000Z","size":11420,"stargazers_count":19,"open_issues_count":13,"forks_count":17,"subscribers_count":11,"default_branch":"develop","last_synced_at":"2025-04-18T00:12:24.355Z","etag":null,"topics":["archethic","blockchain","cryptography","javascript","transaction-chain"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/archethic-foundation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2020-07-01T07:23:25.000Z","updated_at":"2025-04-17T13:17:14.000Z","dependencies_parsed_at":"2023-10-10T19:15:51.703Z","dependency_job_id":"4ca913c1-8107-4675-bb6c-6203a5769881","html_url":"https://github.com/archethic-foundation/libjs","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archethic-foundation%2Flibjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archethic-foundation","download_url":"https://codeload.github.com/archethic-foundation/libjs/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414454,"owners_count":22067272,"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":["archethic","blockchain","cryptography","javascript","transaction-chain"],"created_at":"2025-05-15T20:11:34.261Z","updated_at":"2025-05-15T20:12:15.601Z","avatar_url":"https://github.com/archethic-foundation.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Node.js CI](https://github.com/archethic-foundation/libjs/workflows/Node.js%20CI/badge.svg?branch=master)\n\n# Archethic SDK Javascript\n\nOfficial Archethic Javascript library for Node and Browser.\n\n## Installing\n\n```bash\nnpm install @archethicjs/sdk\n```\n\n## Usage\n\nWhen it comes to private data manipulation, your application has two options :\n\n1. **Standalone :** store private keys on your own\n2. **WalletRPC :** delegate sensitive operations to a Wallet application. (**recommended**, but still Alpha)\n\nThe second option is strongly preferable : it preserves you from security problematics. When your web application needs to perform a sensitive operation (signing a Transaction, reading a Transaction secrets), it will ask **Archethic Wallet** application to perform it.\nThat way, cryptographic secrets never leak from the **Archethic Wallet**.\n\nThe only requirement is user has to run an **Archethic Wallet** on their computer.\n\n\u003e If your application does not perform any sensitive operation, **WalletRPC** is probably not necessary.\n\n### Using the network with WalletRPC\n\nThis library aims to provide an easy way to interact with Archethic network.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\") // Endpoint is the Archethic Wallet RPC server\nawait archethic.connect(); // Connect to the endpoint to retrieve the nearest endpoints\n\nconsole.log(archethic)\n{\n   transaction: ..., // module to manage transaction\n   account: ..., // module to manage keychains and account\n   network: ..., // module to fetch information from the network\n   rpcWallet: ..., /// module to interact with WalletRPC\n}\n```\n\n### Using the network without WalletRPC\n\nThis library aims to provide an easy way to interact with Archethic network.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect(); // Connect to the endpoint to retrieve the nearest endpoints\n\nconsole.log(archethic)\n{\n   transaction: ..., // module to manage transaction\n   account: ..., // module to manage keychains and account\n   network: ..., // module to fetch information from the network\n   ...\n}\n```\n\n**Note**: `archethic.connect()` is useful but not mandatory. In the case of using a website on HTTPS, making a query to a node through HTTP creates a **Mixed content** issue. To avoid this issue, we can use directly `new Archethic(httpsEndpoint)` which will be used as fallback.\n\nIf you still want to use the nearest point while being on an HTTPS website, you could call a server endpoint to make the query for you.\n\n## API\n\n  \u003cdetails\u003e\n   \u003csummary\u003eAccount\u003c/summary\u003e\n\n### newKeychainTransaction(keychain, transactionChainIndex)\n\nCreates a new transaction to build (or update) a keychain by embedding the on-chain encrypted wallet.\n\n- `keychain` The keychain to create\n- `transactionChainIndex` The index of the transaction created (0 for new keychain)\n\n#### Example of keychain creation\n\n```js\nimport Archethic, { Crypto, Keychain } from \"@archethicjs/sdk\";\n\nconst accessSeed = \"myseed\";\nconst { publicKey } = Crypto.deriveKeyPair(accessSeed, 0);\nconst keychain = new Keychain(Crypto.randomSecretKey())\n  .addService(\"uco\", \"m/650'/0/0\")\n  .addAuthorizedPublicKey(publicKey);\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\nconst tx = archethic.account.newKeychainTransaction(keychain, 0);\n// The transaction can then be signed with origin private key\n```\n\n#### Example of keychain update\n\n```js\nimport Archethic, { Crypto } from \"@archethicjs/sdk\";\n\nconst accessSeed = \"myseed\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\nlet keychain = await archethic.account.getKeychain(accessSeed);\nkeychain.addService(\"mywallet\", \"m/650'/1/0\");\n\n// determine the new transaction index\nconst keychainGenesisAddress = Crypto.deriveAddress(keychain.seed, 0);\nconst transactionChainIndex = await archethic.transaction.getTransactionIndex(keychainGenesisAddress);\n\nconst tx = archethic.account.newKeychainTransaction(keychain, transactionChainIndex);\n// The transaction can then be signed with origin private key\n```\n\n### newAccessKeychainTransaction(seed, keychainAddress)\n\nCreates a new keychain access transaction to allow a seed and its key to access a keychain\n\n- `seed` Keychain access's seed\n- `keychainAddress` Keychain's tx address\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nconst tx = archethic.account.newAccessKeychainTransaction(\"myseed\", keychainAddress);\n// The transaction can then be signed with origin private key\n```\n\n### getKeychain(seed)\n\nRetrieve a keychain from the keychain access transaction and decrypt the wallet to retrieve the services associated\n\n- `seed` Keychain access's seed\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\nawait archethic.connect()\n\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed)\nconsole.log(keychain)\n{\n  version: 1,\n  seed: \"masterKeychainSeed\",\n  authorizedPublicKeys: [ Uint8Array(34) ],\n  services: {\n    uco: {\n      derivationPath: \"m/650'/0/0\"\n    }\n  }\n}\n```\n\n**Once retreived the keychain provide the following methods:**\n\n#### buildTransaction(tx, service, index, suffix)\n\nGenerate `address`, `previousPublicKey`, `previousSignature` of the transaction and\nserialize it using a custom binary protocol, based on the derivation path, curve and hash algo of the service given in param.\n\n- `tx` is an instance of `TransactionBuilder`\n- `service` is the service name to use for getting the derivation path, the curve and the hash algo\n- `index` is the number of transactions in the chain, to generate the actual and the next public key (see the cryptography section)\n- `suffix`: Additional information to add to a service derivation path (default to empty)\n\nReturn is the signed `TransactionBuilder`. Notice that the function also sign the `TransactionBuilder` given in param, so getting the return is not mandatory\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\n\nconst index = archethic.transaction.getTransactionIndex(keychain.deriveAddress(\"uco\", 0));\n/*const signedTx =*/ keychain.buildTransaction(tx, \"uco\", index);\n```\n\n#### deriveAddress(service, index, suffix)\n\nDerive an address for the given service at the index given\n\n- `service`: Service name to identify the derivation path to use\n- `index`: Chain index to derive (default to 0)\n- `suffix`: Additional information to add to a service derivation path (default to empty)\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\nconst genesisUCOAddress = keychain.deriveAddress(\"uco\", 0);\n```\n\n#### deriveKeypair(service, index, suffix)\n\nDerive a keypair for the given service at the index given\n\n- `service`: Service name to identify the derivation path to use\n- `index`: Chain index to derive (default to 0)\n- `suffix`: Additional information to add to a service derivation path (default to empty)\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\nconst { publicKey } = keychain.deriveKeypair(\"uco\", 0);\n```\n\n#### ecEncryptServiceSeed(service, publicKeys)\n\nUse ec encryption on the seed for the list of authorizedPublicKeys\n\n- `service`: Service name to identify the derivation path to use\n- `authorizedPublicKeys`: List of public keys to encrypt the service seed\n\n```js\nimport Archethic, { Keychain, Crypto } from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"http://testnet.archethic.net\");\nawait archethic.connect();\n\nconst keychain = new Keychain(Crypto.randomSecretKey()).addService(\"uco\", \"m/650'/uco\");\n\nconst storageNonce = await archethic.network.getStorageNoncePublicKey();\n\nconst { secret, authorizedPublicKeys } = keychain.ecEncryptServiceSeed(\"uco\", [storageNonce]);\n// secret and authorizedPublicKeys can be used to create an ownership\nconst tx = archethic.transaction.new().addOwnership(secret, authorizedPublicKeys);\n```\n\n#### toDID()\n\nReturn a Decentralized Identity document from the keychain. (This is used in the transaction's content of the keychain tx)\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\nconst did  = keychain.toDID()\nconsole.log(did)\n{\n  \"@context\": [\n     \"https://www.w3.org/ns/did/v1\"\n  ],\n  \"id\": \"did:archethic:keychain_address\",\n  \"authentification\": servicesMaterials, //list of public keys of the services\n  \"verificationMethod\": servicesMaterials //list of public keys of the services\n}\n```\n\n#### addService(name, derivationPath, curve, hashAlgo)\n\nAdd a service into the keychain\n\n- `name`: Name of the service to add\n- `derivationPath`: Crypto derivation path\n- `curve`: Elliptic curve to use\n- `hashAlgo`: Hash algo\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\nkeychain.addService(\"nft1\", \"m/650'/1/0\")\nconsole.log(keychain)\n{\n  version: 1,\n  seed: \"mymasterseed\",\n  authorizedPublicKeys: [ Uint8Array(34) ],\n  services: {\n    uco: {\n      derivationPath: \"m/650'/0/0\",\n      curve: \"ed25519\",\n      hashAlgo: \"sha256\"\n    },\n    nft1: {\n      derivationPath: \"m/650'/1/0\",\n      curve: \"ed25519\",\n      hashAlgo: \"sha256\"\n    }\n  }\n}\n```\n\n#### removeService(name)\n\nRemove a service from the keychain\n\n- `name`: Name of the service to add\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\nkeychain.removeService(\"nft1\");\n```\n\n#### addAuthorizedPublicKey(publicKey)\n\nAuthorize a key to access the keychain\n\n- `publicKey`: The public key (type: Uint8Array)\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst accessSeed = \"myseed\";\nconst { publicKey } = Crypto.deriveKeyPair(accessSeed, 0);\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\nkeychain.addAuthorizedPublicKey(publicKey);\n```\n\n#### removeAuthorizedPublicKey(publicKey)\n\nUnauthorized a key to access the keychain\n\n- `publicKey`: The public key (type: Uint8aArray)\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst accessSeed = \"myseed\";\nconst { publicKey } = Crypto.deriveKeyPair(accessSeed, 0);\nconst keychain = await archethic.account.getKeychain(accessKeychainSeed);\nkeychain.removeAuthorizedPublicKey(publicKey);\n```\n\n  \u003c/details\u003e\n\n  \u003cdetails\u003e\n    \u003csummary\u003eTransactions\u003c/summary\u003e\n\n### new()\n\nTo create a new transaction instance to build and to send to the network\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst txBuilder = archethic.transaction.new();\n```\n\nThe transaction builder instance contains the following methods:\n\n#### setType(type)\n\nDefine the transaction type\n\n- `type` is the string defining the type of transaction to generate (\"keychain\", \"keychain_access\", \"transfer\", \"hosting\", \"code_proposal\", \"code_approval\", \"token\")\n\n#### setContract(contract)\n\nAdd the contract in the `data.contract` section of the transaction\n\n- `contract` is an object with following keys:\n  - `bytecode` Uint8Array of the compiled wasm code compressed using zip\n  - `manifest` the manifest of the contrat containing actions and functions spec\n\n```js\nconst bytecode = fs.readFileSync(\"./dist/contract.wasm\")\nconst manifestFile = fs.readFileSync('./dist/manifest.json', 'utf-8')\nconst manifest = JSON.parse(manifestFile)\n\nconst contract = new Contract(bytecode, manifest)\n\nconst txBuilder = archethic.transaction.new().setType(\"contract\").setContract(contract)\n// or use Contract function\nimport { Contract } from \"@archethicjs/sdk\"\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\nconst tx = Contract.newContractTransaction(archethic, contract, seed)\n```\n\n#### setGenerateEncryptedSeedSC(flag)\n\nSet a flag to request a wallet to add the chain seed in the ownership of the transaction to create a smart contract.\nThis function is only usefull when sending / signing the transaction through a wallet. Signing and sending the transaction directly to the node will not use this flag.\n\n- `flag` is a boolean to request the node to add the chain seed in the ownership\n\n#### setContent(content)\n\nAdd the content in the `data.content` section of the transaction\n\n- `content` is a string defining the smart contract\n\n#### addOwnership(secret, authorizedKeys)\n\nAdd an ownership in the `data.ownerships` section of the transaction with a secret and its related authorized public keys to be able to decrypt it.\nThis aims to prove the ownership or the delegatation of some secret to a given list of public keys.\n\n- `secret` is the hexadecimal encoding or Uint8Array representing the encrypted secret\n- `authorizedKeys` is a list of object represented by - `publicKey` is the hexadecimal encoding or Uint8Array representing the public key - `encryptedSecretKey` is the hexadecimal encoding or Uint8Array representing the secret key encrypted with the public key (see `ecEncrypt`)\n\n#### addUCOTransfer(to, amount)\n\nAdd a UCO transfer to the `data.ledger.uco.transfers` section of the transaction\n\n- `to` is hexadecimal encoding or Uint8Array representing the transaction address (recipient) to receive the funds\n- `amount` is the number of uco to send (in Big Int ref function `parseBigInt`)\n\n#### addTokenTransfer(to, amount, tokenAddress, tokenId)\n\nAdd a token transfer to the `data.ledger.token.transfers` section of the transaction\n\n- `to` is hexadecimal encoding or Uint8Array representing the transaction address (recipient) to receive the funds\n- `amount` is the number of uco to send (in Big Int ref function `parseBigInt`)\n- `tokenAddress` is hexadecimal encoding or Uint8Array representing the token's address to spend\n- `tokenId` is the ID of the token to send (default to: 0)\n\n#### addRecipient(to, action, args)\n\nAdds a recipient to call the smart contract's \"transaction\" action.\n\n- `to` is the contract's address in hexadecimal or Uint8Array\n- `action` is the name of the action\n- `args` is an object containing the parameter for the contract action. This parameter is not mandatory\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addRecipient(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", \"increment\")\n  .addRecipient(\"0000bc96b1a9751d3750edb9381a55b5b4e4fb104c10b0b6c9a00433ec464637bfab\", \"vote\", {name: \"Dr. Who\"});\n```\n\n#### build(seed, index, curve, hashAlgo)\n\nGenerate `address`, `previousPublicKey`, `previousSignature` of the transaction and\nserialize it using a custom binary protocol.\n\n- `seed` is hexadecimal encoding or Uint8Array representing the transaction chain seed to be able to derive and generate the keys\n- `index` is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)\n- `curve` is the elliptic curve to use for the key generation (can be \"ed25519\", \"P256\", \"secp256k1\") - default o \"P256\"\n- `hashAlgo` is the hash algorithm to use to generate the address (can be \"sha256\", \"sha512\", \"sha3-256\", \"sha3-512\", \"bake2b\") - default to \"sha256\"\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42)\n  .build(\"mysuperpassphraseorseed\", 0);\n```\n\n#### originSign(privateKey)\n\nSign the transaction with an origin device private key\n\n- `privateKey` is hexadecimal encoding or Uint8Array representing the private key to generate the origin signature to able to perform the ProofOfWork and authorize the transaction\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\n    \"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\",\n    0.42\n  )\n  .build(\"mysuperpassphraseorseed\", 0);\n  .originSign(originPrivateKey);\n```\n\n#### toJSON()\n\nExport the transaction generated into JSON\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\n    \"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\",\n    0.42\n  )\n  .build(\"mysuperpassphraseorseed\", 0);\n  .toJSON();\n```\n\n### Interacting with other signer (hardware for example)\n\n#### previousSignaturePayload()\n\nGet an Uint8Array payload to be signed with user seed\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42);\n\nconst signaturePayload = tx.previousSignaturePayload();\n```\n\n#### setPreviousSignatureAndPreviousPublicKey(prevSign, prevPubKey)\n\nSetter method for the transaction's previous signature and previous public key.\n\n- `prevSign` is hexadecimal encoding or Uint8Array previous signature of the transaction\n- `prevPubKey` is hexadecimal encoding or Uint8Array previous public key of the transaction\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42);\n\nconst signaturePayload = tx.previousSignaturePayload();\nconst prevSign = someFunctionToGetSignature(signaturePayload);\nconst prevPubKey = someFunctionToGetPubKey();\ntx.setPreviousSignatureAndPreviousPublicKey(prevSign, prevPubKey);\n```\n\n#### setAddress(address)\n\nSetter method for the transaction's address.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42);\n\nconst txAddress = someFunctionToGetTxAddress();\ntx.setAddress(txAddress);\n```\n\n#### originSignaturePayload()\n\nGet an Uint8Array payload to be signed with the origin private key of the device.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42)\n  .build(seed, originPrivateKey);\n\nconst originPayload = tx.originSignaturePayload();\n```\n\n#### setOriginSign(signature)\n\nSetter method for the transaction's origin signature.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42)\n  .build(\"mysuperpassphraseorseed\", 0);\n\nconst originPayload = tx.originSignaturePayload();\nconst originSignature = someFunctionToGetSignature(originPayload);\ntx.setOriginSign(originSignature);\n```\n\n#### send(confirmationThreshold, timeout)\n\n- `confirmationThreshold` is a percentage (0 to 100) where the transaction is considered as validated. This is used to trigger `requiredConfirmation` event. Default value is to 100. This parameter is not mandatory\n- `timeout` is the number of second to wait until timeout event is triggered. Default value is to 60 sec. This parameter is not mandatory\n\nSend a transaction to the endpoint and subscribe the node to get confirmation or validation error.\nWhen an update of the validation is received from the subscription, some events are triggered and associated function are called (see function **on** bellow)\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42)\n  .build(\"mysuperpassphraseorseed\", 0)\n  .originSign(privateKey)\n  .on(\"confirmation\", (nbConf, maxConf) =\u003e console.log(nbConf, maxConf))\n  .send();\n```\n\n#### on(event, handler)\n\nSubscribe to a specific event.\n\n- `event` is the name of the event to subscribe\n- `handler` is a function which will be called when event is triggered\n\navailable events:\n\n- `'sent'` triggered when transaction is sent. handler param: no parameter\n- `'confirmation'` triggered when a new replication is received. handler params: number of replication, maximum number of replication expected\n- `'fullConfirmation'` triggered when the number of replication = the number of maximum replication expected. handler param: maximum number of replication expected\n- `'requiredConfirmation'` triggered when the number of replication is equal or overpass for the first time the maximum replication \\* confirmationThreshold. handler param: number of replication\n- `'error'` triggered when an error is encountered during validation. handler params: context, reason\n  - Context is a string with \"INVALID_TRANSACTION\" for error in the transaction itself like \"Insufficient funds\" or \"NETWORK_ISSUE\" for error in mining like \"Consensus error\".\n- `'timeout'` triggered 60 sec after sending the transaction. Timeout is cleared when `'fullConfirmation'`, `'error'` or `'requiredConfirmation'` events are triggered. handler param: number of replication received yet\n\nMutiple function can be assigned to a same event. Just call function `on` mutiple times for the same event.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addUCOTransfer(\"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\", 0.42)\n  .build(\"mysuperpassphraseorseed\", 0)\n  .originSign(privateKey)\n  .on(\"sent\", () =\u003e console.log(\"transaction sent !\"))\n  .on(\"confirmation\", (nbConf, maxConf) =\u003e console.log(nbConf, maxConf))\n  .on(\"fullConfirmation\", (nbConf) =\u003e console.log(nbConf))\n  .on(\"requiredConfirmation\", (nbConf) =\u003e console.log(nbConf))\n  .on(\"error\", (context, reason) =\u003e console.log(context, reason))\n  .on(\"timeout\", (nbConf) =\u003e console.log(nbConf))\n  .send(60); // confirmationThreshold: 60\n```\n\n#### unsubscribe(event)\n\nUnsubscribe to a specific event or all events.\n\n- `event` is the name of the event (same as **on** function). This parameter is not mandatory, if the event name is empty all events are unsubscribed.\n\n### getTransactionIndex(address)\n\nQuery a node to find the length of the chain to retrieve the transaction index\n\n- `address` Transaction address (in hexadecimal)\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nawait archethic.connect();\nconst txIndex = await archethic.transaction.getTransactionIndex(\n  \"00b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\"\n);\n// 0\n```\n\n### getTransactionFee(tx)\n\nQuery a node to fetch the tx fee for a given transaction\n\n- `tx` Generated transaction\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\nconst tx = ...\nconst fee = await archethic.transaction.getTransactionFee(tx)\nconsole.log(fee)\n{\n  fee: 11779421, // Big Int format\n  rates: {\n    eur: 0.086326,\n    usd: 0.084913\n  }\n}\n```\n\n### getTransactionOwnerships(address)\n\nQuery a node to find the ownerships (secrets and authorized keys) to given transaction's address\n\n- `address`: Transaction's address\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nconst ownerships = await archethic.transaction.getTransactionOwnerships(tx.address);\nconsole.log(ownerships)[\n  {\n    secret: \"...\",\n    authorizedPublicKeys: [\n      {\n        publicKey: \"...\",\n        encryptedSecretKey: \"\"\n      }\n    ]\n  }\n];\n```\n\n  \u003c/details\u003e\n\n  \u003cdetails\u003e\n    \u003csummary\u003eNetwork\u003c/summary\u003e\n\n### getToken(tokenAddress)\n\nQuery a node to get the token definition (based on [AEIP2](https://github.com/archethic-foundation/aeip/blob/main/AEIP-2.md)) from an address.\nReturns also `genesis` address and `id`\n\n- `tokenAddress` is the transaction address of the token.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nawait archethic.connect();\nconst token = await archethic.network.getToken(tokenAddress);\nconsole.log(token);\n{\n  collection: [],\n  decimals: 8,\n  genesis: '0000D6979F125A91465E29A12F66AE40FA454A2AD6CE3BB40099DBDDFFAF586E195A',\n  id: '9DC6196F274B979E5AB9E3D7A0B03FEE3E4C62C7299AD46C8ECF332A2C5B6574',\n  name: 'Mining UCO rewards',\n  properties: {},\n  supply: 3340000000000000, // Big Int format\n  symbol: 'MUCO',\n  type: 'fungible'\n}\n```\n\n### callFunction(contractAddress, functionName, args)\n\nCall a Smart Contract's exported function with given args.\n\n- `contractAddress` is the address of the contract (usually latest or genesis)\n- `functionName` is the exported function to call\n- `args` is the list of arguments to call the function with\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst response = await archethic.network.callFunction(\"0000AB...CD\", \"add\", [1, 2]);\nconsole.log(response);\n3;\n```\n\n### getBalance(address)\n\nQuery a node to fetch the last balance of the given address\n\n- `address` is the address of the account to get the balance from\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nawait archethic.connect()\n\nconst balance = await archethic.network.getBalance(accountAddress);\nconsole.log(balance)\n{\n  uco: 100000000,\n  tokens: [{\n    address: '209DFA0C.....',\n    tokenId: 'ABD829FD.....',\n    amount: 100000000\n  }]\n}\n```\n\n### addOriginKey(originPublicKey, certificate)\n\nQuery a node to add a new origin public to be authorized to sign transaction with the corresponding private key (see OriginSign).\n\n- `originPublicKey` is the public key to be added.\n- `certificate` is the certificate that prove the public key is allowed to be added.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nawait archethic.connect();\nconst response = await archethic.network.addOriginKey(originPublicKey, certificate);\n\nconsole.log(response);\n{\n  transaction_address: \"...\";\n  status: \"pending\";\n}\n```\n\n### getStorageNoncePublicKey()\n\nFetch the public key of the shared storage node key\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\n\nawait archethic.connect();\n\nconst storageNoncePublicKey = await archethic.network.getStorageNoncePublicKey();\n// 00b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\n```\n\n### getContractCode(address)\n\nReturn the contract code\n\n- `address`: string or Uint8Array of the contract address\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\nawait archethic.connect()\n\nconst res = archethic.network.getContractCode(\"0001234...\")\nconsole.log(res)\n{\n  code: \"...\",\n  contract: {\n    bytecode: \"00231654\",\n    manifest: {\n      abi: {\n        state: ...,\n        functions: []\n      }\n    }\n  }\n}\n```\n\n### getOracleData(timestamp)\n\nFetch the OracleChain data\n\n- `timestamp`: UNIX timestamp (optional)\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\nawait archethic.connect()\n\nconst oracleData = await archethic.network.getOracleData()\nconsole.log(oracleData)\n{\n  timestamp: ...,\n  services: {\n    uco: {\n      eur: ...,\n      usd: ...\n    }\n  }\n}\n```\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\nawait archethic.connect()\n\nconst oracleData = await archethic.network.getOracleData(timestamp)\nconsole.log(oracleData)\n{\n  services: {\n    uco: {\n      eur: ...,\n      usd: ...\n    }\n  }\n}\n```\n\n### rawGraphQLQuery(query)\n\nQuery the GraphQL API of the node with a custom graphQL query that fits your needs.\n\n- `query`: The graphQL query to send to the node\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\");\nawait archethic.connect();\n\nconst query = `\nquery {\n  transactions(page:1) {\n    address\n    chainLength\n    data {\n      code\n    }\n    type\n    version\n  }\n}\n`;\n\nconst response = await archethic.network.rawGraphQLQuery(query);\n```\n\n### subscribeToOracleUpdates(handler)\n\nSubscribe to get the real time updates of the OracleChain\n\n- `handler`: Callback to handle the new data\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\nawait archethic.connect()\n\nawait archethic.network.subscribeToOracleUpdates(console.log)\n{\n  timestamp: ...,\n  services: {\n    uco: {\n      eur: ...,\n      usd: ...\n    }\n  }\n}\n```\n\n  \u003c/details\u003e\n\n  \u003cdetails\u003e\n  \u003csummary\u003eWallet RPC\u003c/summary\u003e\n\n### setOrigin(origin)\n\nConfigures the DApp identity. DApp identity will be sent to WalletRPC.\n\nOn operations requiring user's confirmation, that identity might be displayed.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n```\n\n### onconnectionstatechange(callback)\n\nListens to connection state changes between DApp and WalletRPC.\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"ws://localhost:12345\")\nawait archethic.connect()\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n})\n\narchethic.rpcWallet.onconnectionstatechange(\n  (rpcConnectionState) {\n    console.log(`WalletRPC connection state changed : ${rpcConnectionState}`)\n  }\n)\n\n// To stop listening :\narchethic.rpcWallet.unsubscribeconnectionstatechange()\n```\n\n### getAccounts()\n\nReads a concise accounts list from ArchethicWallet.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\narchethic.rpcWallet.getAccounts().then((accounts) =\u003e {\n  accounts.forEach((account) =\u003e {\n    console.log(`\\t ${JSON.stringify(account)}`);\n  });\n});\n```\n\n### getServices()\n\nReads a concise services list from ArchethicWallet.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url \"https://great_app.com\"\n});\n\narchethic.rpcWallet.getServices().then((services) =\u003e {\n  services.forEach((service) =\u003e {\n    console.log(`\\t ${JSON.stringify(service)}`);\n  });\n});\n```\n\n### onAccountUpdate(accountName, callback) : RpcSubscription\n\nListens to an account's changes.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\nconst subscription = await archethic.rpcWallet.onAccountUpdate(\"account name\", (account) =\u003e {\n  console.log(JSON.stringify(account));\n});\n```\n\n### onCurrentAccountChange(callback) : RpcSubscription\n\nListens account selection in wallet.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\nconst subscription = await archethic.rpcWallet.onCurrentAccountChange((account) =\u003e {\n  console.log(JSON.stringify(account));\n});\n```\n\n### refreshCurrentAccount()\n\nRequest the wallet to refresh current account info\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\nawait archethic.rpcWallet.refreshCurrentAccount();\n// Wallet account is refreshed with last blockchain informations\n```\n\n### unsubscribe(rpcSubscription)\n\nStops any subscription to Wallet.\n\n```js\nimport Archethic from \"@archethicjs/sdk\"\n\nconst archethic = new Archethic(\"ws://localhost:12345\")\nawait archethic.connect()\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n})\n\nconst subscription // subscription from a previous call (onAccountUpdate for example)\n\nawait archethic.rpcWallet.unsubscribe(subscription)\n```\n\n### sendTransaction(transaction)\n\nAsks ArchethicWallet to sign and send a transaction.\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"token\")\n  .setContent(\n    '{ \"name\": \"NFT 001\", \"supply\": 100000000, \"type\": \"non-fungible\", \"symbol\": \"NFT1\", \"aeip\": [2], \"properties\": {}}'\n  );\n\narchethic.rpcWallet\n  .sendTransaction(tx)\n  .then((sendResult) =\u003e {\n    console.log(JSON.stringify(sendResult));\n    // { transactionAddress: \"asdfasfsadf\", nbConfirmations: 3, maxConfirmations: 3 }\n  })\n  .catch((sendError) =\u003e {\n    console.log(JSON.stringify(sendResult));\n  });\n```\n\n### signTransactions([transaction])\n\nAsks ArchethicWallet to sign multiple transactions.\n\n```js\nimport Archethic, { Utils } from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\nconst tx = archethic.transaction\n  .new()\n  .setType(\"transfer\")\n  .addTokenTransfer(\"0001ABCD...\", Utils.parseBigInt('12'), \"00001234...\", 0)\n  .addRecipient(\"0001ABCD...\", \"swap\");\n\narchethic.rpcWallet\n  .signTransactions(tx)\n  .then((signedResult) =\u003e {\n    console.log(JSON.stringify(signedResult));\n    signedResult.forEach((signedTransaction) =\u003e {\n      console.log(JSON.stringify(signedTransaction));\n      // {address: \"000ef....\", previousPublicKey: \"00045b...\", previousSignature: \"000ef....\", originSignature: \"00045b...\"}\n    });\n  })\n  .catch((signedError) =\u003e {\n    console.log(JSON.stringify(signedError));\n  });\n```\n\n### addService(name)\n\nAdd a service in the keychain\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\narchethic.rpcWallet\n  .addService(\"myService\")\n  .then((result) =\u003e {\n    console.log(JSON.stringify(result));\n  })\n  .catch((error) =\u003e {\n    console.log(error);\n  });\n```\n\n### keychainDeriveKeypair(serviceName, index, pathSuffix)\n\nDerive a keypair for the given service at the index given and get the public key\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\narchethic.rpcWallet.keychainDeriveKeypair(\"myService\", 1, \"suffix\").then((result) =\u003e {\n  console.log(result[\"publicKey\"]);\n});\n```\n\n### keychainDeriveAddress(serviceName, index, pathSuffix)\n\nDerive an address for the given service at the index given\n\n```js\nimport Archethic from \"@archethicjs/sdk\";\n\nconst archethic = new Archethic(\"ws://localhost:12345\");\nawait archethic.connect();\n\nawait archethic.rpcWallet.setOrigin({\n  name: \"My DApp\",\n  url: \"https://great_app.com\"\n});\n\narchethic.rpcWallet.keychainDeriveAddress(\"myService\", 1, \"suffix\").then((result) =\u003e {\n  console.log(result[\"address\"]);\n});\n```\n\n  \u003c/details\u003e\n\n  \u003cdetails\u003e\n  \u003csummary\u003eCryptography\u003c/summary\u003e\n\n  \u003cbr /\u003e\n\n### deriveKeyPair(seed, index, curve)\n\nIt creates a new keypair into hexadecimal format\n\n- `seed` is hexadecimal encoding or Uint8Array representing the transaction chain seed to be able to derive and generate the keys\n- `index` is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)\n- `curve` is the elliptic curve to use for the key generation (can be \"ed25519\", \"P256\", \"secp256k1\") - default to: \"ed25519\"\n- `origin_id` is the origin of the public key (can be 0 for \"on chain wallet\", 1 for \"software\" or 2 for \"tpm\") - default to: 1\n\n```js\nimport { Crypto } from \"@archethicjs/sdk\";\nconst { publicKey: publicKey, privateKey: privateKey } = Crypto.deriveKeyPair(\"mysuperpassphraseorseed\", 0);\n// publicKey =\u003e 0100048cac473e46edd109c3ef59eec22b9ece9f99a2d0dce1c4ccb31ce0bacec4a9ad246744889fb7c98ea75c0f0ecd60002c07fae92f23382669ca9aff1339f44216\n```\n\n### deriveAddress(seed, index, curve, hashAlgo)\n\nIt creates a transaction address by extract the public key from the key derivation and hash it into a hexadecimal format\n\n- `seed` is hexadecimal encoding or Uint8Array representing the transaction chain seed to be able to derive and generate the keys\n- `index` is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)\n- `curve` is the elliptic curve to use for the key generation (can be \"ed25519\", \"P256\", \"secp256k1\") - Default to \"ed25519\"\n- `hashAlgo` is the hash algorithm to create the address (can be \"sha256\", \"sha512\", \"sha3-256\", \"sha3-512\", \"blake2b\") - default to \"sha256\"\n\n```js\nimport { Crypto } from \"@archethicjs/sdk\";\nconst address = Crypto.deriveAddress(\"mysuperpassphraseorseed\", 0);\n// Address: 00004195d45987f33e5dcb71edfa63438d5e6add655b216acfdd31945d58210fe5d2\n```\n\nIt creates a new keypair and extract the public key into hexadecimal format\n\n- `seed` is hexadecimal encoding or Uint8Array representing the transaction chain seed to be able to derive and generate the keys\n- `index` is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)\n- `curve` is the elliptic curve to use for the key generation (can be \"ed25519\", \"P256\", \"secp256k1\")\n\n```js\nimport { Crypto } from \"@archethicjs/sdk\";\nconst publicKey = Crypto.derivePublicKey(\"mysuperpassphraseorseed\", 0);\n```\n\n### ecEncrypt(data, publicKey)\n\nPerform an ECIES encryption using a public key and a data\n\n- `data` Data to encrypt\n- `publicKey` Public key to derive a shared secret and for whom the content must be encrypted\n\n```js\nimport { Crypto } from \"@archethicjs/sdk\";\nconst cipher = Crypto.ecEncrypt(\n  \"dataToEncrypt\",\n  \"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\"\n);\n```\n\n### ecDecrypt(cipher, privateKey)\n\nPerform an ECIES decryption using a private key and an encrypted data\n\n- `cipher` Data to decrypt\n- `privateKey` Private key to derive a shared secret and for whom the content must be decrypted\n\n```js\nimport { Crypto } from \"@archethicjs/sdk\";\nconst cipher = Crypto.ecDecrypt(\"dataToDecrypt\", \"36f7753a63188eabaf4891c5724d346da58160cdc386ebf248603724d1796cd3\");\n```\n\n### aesEncrypt(data, publicKey)\n\nPerform an AES encryption using a key and a data\n\n- `data` Data to encrypt\n- `key` Symmetric key\n\n```js\nimport { Crypto } from \"@archethicjs/sdk\";\nconst cipher = Crypto.aesEncrypt(\n  \"dataToEncrypt\",\n  \"0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646\"\n);\n```\n\n  \u003c/details\u003e\n\n  \u003cdetails\u003e\n  \u003csummary\u003eUtils\u003c/summary\u003e\n\n### formatBigInt(number, decimals)\n\nConvert a big int number to a x decimals string (mainly use to display token amount)\n\n- `number` Big Int number to convert to decimals number\n- `decimals` number of decimals needed (default to 8)\n\n```js\nimport { Utils } from \"@archethicjs/sdk\";\nUtils.formatBigInt(BigInt(1_253_450_000));\n// '12.5345'\nUtils.formatBigInt(BigInt(12_534_500), 6);\n// '12.5345'\n```\n\n### parseBigInt(number, decimals)\n\nConvert a string into a BigInt number\n\n- `number` decimals number to convert to Big Int number\n- `decimals` number of decimals (default to 8)\n\n```js\nimport { Utils } from \"@archethicjs/sdk\";\nUtils.parseBigInt('12.5345');\n// 1_253_450_000\nUtils.parseBigInt('12.5345', 6);\n// 12_534_500\n```\n\n### originPrivateKey\n\nGetting the default origin Key :\n\n```js\nimport Archethic, { Utils } from \"@archethicjs/sdk\"\nconst originPrivateKey = Utils.originPrivateKey\n\nconst archethic = new Archethic(\"https://testnet.archethic.net\")\n\nconst tx = archethic.transaction.new()\n...\ntx.originSign(originPrivateKey)\n```\n\n  \u003c/details\u003e\n  \u003cdetails\u003e\n  \u003csummary\u003eContract\u003c/summary\u003e\n\n  \u003cbr /\u003e\n\n  ### newContractTransaction(archethic, contract, contractSeed, txData?)\n\n  Create a new contract transaction injecting the bytecode, manifest and the authorized public key encryption to allow node to emit transaction on your behalf.  Returned transaction is already signed.\n\n  ```js\n  import Archethic, { Utils, Contract } from \"@archethicjs/sdk\"\n  const archethic = new Archethic(\"https://testnet.archethic.net\")\n\n  const bytecode = fs.readFileSync(\"./dist/contract.wasm\")\n  const manifestFile = fs.readFileSync('./dist/manifest.json', 'utf-8')\n  const manifest = JSON.parse(manifestFile)\n\n  const contract = new Contract(bytecode, manifest)\n\n  // txData is optional\n  const txData = {\n    content: \"content\",\n    ledger: {\n      uco: {\n        transfers: [{to: \"1234\", amount: Utils.parseBigInt(\"10\")}]\n      }\n    }\n  }\n  \n  const tx = await Contract.newContractTransaction(archethic, contract, contractSeed, txData)\n\n  tx\n    .originSign(Utils.originPrivateKey)\n    .on(\"requiredConfirmation\", () =\u003e console.log(\"ok deployed\"))\n    .on(\"error\", (context, reason) =\u003e console.error(reason))\n    .send();\n  ```\n\n  ### updateContractTransaction(archethic, contractAddress, contract)\n\n  Create a new transaction containing the recipient filled with appropriated function to update a contract code\n\n  ```js\n  import Archethic, { Utils, Contract } from \"@archethicjs/sdk\"\n  const archethic = new Archethic(\"https://testnet.archethic.net\")\n\n  const bytecode = fs.readFileSync(\"./dist/contract.wasm\")\n  const manifestFile = fs.readFileSync('./dist/manifest.json', 'utf-8')\n  const manifest = JSON.parse(manifestFile)\n\n  const contract = new Contract(bytecode, manifest)\n\n  const tx = await Contract.updateContractTransaction(archethic, contractAddress, contract)\n\n  tx\n    .build(seed, index)\n    .originSign(Utils.originPrivateKey)\n    .on(\"requiredConfirmation\", () =\u003e console.log(\"ok updated\"))\n    .on(\"error\", (context, reason) =\u003e console.error(reason))\n    .send();\n  ```\n\n  \u003c/details\u003e\n\n## Running the tests\n\n```bash\nnpm run test\n```\n\n## Examples\n\nSome examples are present to see how to use the SDK\n\n### Keychain\n\n```bash\ncd example/keychain\nnpm install\nnpm run start\n```\n\n### TransactionBuilder\n\n```bash\ncd example/transactionBuilder\nnpm install\nnpm run start\n```\n\n### Miscellaneous\n\nIf you want to leverage React for your DApp, you have to rely on [react-app-rewired](https://www.npmjs.com/package/react-app-rewired) to avoid errors regarding NodeJS module not accessible in the Webpack build.\n\nYou can see how to resolve the issues in this [article](https://www.alchemy.com/blog/how-to-polyfill-node-core-modules-in-webpack-5)\n\n## Licence\n\nAGPL3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchethic-foundation%2Flibjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchethic-foundation%2Flibjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchethic-foundation%2Flibjs/lists"}