Skip to content

Commit

Permalink
Added typescript instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
katieclay committed Oct 22, 2024
1 parent 768683d commit 05a77a8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitbook/contents/hc/2_addsub/1_write-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ from eth_abi import abi as ethabi

The last two, `Web3` and `eth_abi`, are established `PyPI` libraries. The third library, `offchain_utils`, was developed by the Boba Foundation. You can view the [library](https://github.com/bobanetwork/rundler-hc/blob/boba-develop/hybrid-compute/offchain/offchain_utils.py) on our Github.

Note: if writing your handler in TypeScript, import the Hybrid Compute SDK and its utility functions like this:

```typescript
import { HybridComputeSDK } from '@bobanetwork/aa-hc-sdk-server';

const sdk = new HybridComputeSDK();

import {
generateResponse,
parseOffchainParameter,
parseRequest,
decodeAbi
} from '@bobanetwork/aa-hc-sdk-server';

// Parse offchain parameters
const parsedParams = parseOffchainParameter(offchainParams);

// Generate a response
const response = generateResponse(request, errorCode, responsePayload);

// Decode ABI-encoded data
const decodedData = decodeAbi(types, data);
```

Now, we can write our function. Let's start by initializing an `err_code` and a `resp` object with values in case of an exception:

```python
Expand Down
21 changes: 21 additions & 0 deletions .gitbook/contents/hc/3_server-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ For any smart contract, with or without an off-chain handler, the next step is t
```python
sdk = HybridComputeSDK()
sdk.create_json_rpc_server_instance()

def main():
print("created server")
sdk.add_server_action("getprice(string)", offchain_getprice)

print("Serving!")
sdk.serve_forever()
```

Note: if working with TypeScript instead of Python, set up your server like this instead:

```typescript
import { HybridComputeSDK } from '@bobanetwork/aa-hc-sdk-server';

const sdk = new HybridComputeSDK();

sdk.createJsonRpcServerInstance()
.addServerAction('myAction', (params) => {
// Handle action
})
.listenAt(3000);
```

## Why is that?
Expand Down

0 comments on commit 05a77a8

Please sign in to comment.