Skip to content

Commit

Permalink
Using Fireblocks Tokenization endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
orman committed Nov 28, 2023
1 parent f325335 commit f8cb28a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 72 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ You can also pass additional arguments:
fireblocks = FireblocksSDK(private_key, api_key, api_base_url="https://api.fireblocks.io", timeout=2.0, anonymous_platform=True)
```

#### Using Fireblocks Tokenization SDK
#### Using Fireblocks Tokenization endpoints
```python
from fireblocks_sdk import FireblocksSDK, FireblocksTokenization, \
ContractUploadRequest

fireblocks = FireblocksSDK(private_key, api_key)
fbTokenization = FireblocksTokenization(fireblocks)

tokens=fbTokenization.get_linked_tokens()
# Get linked tokens
tokens=fireblocks.get_linked_tokens()

# Upload a private contract
contractTemplateRequest=ContractUploadRequest(
name='New Contract Template',
description='description',
Expand All @@ -46,6 +47,6 @@ contractTemplateRequest=ContractUploadRequest(
initializationPhase='ON_DEPLOYMENT',
abi=[]
)
template=fbTokenization.upload_contract_template(contractTemplateRequest)
template=fireblocks.upload_contract_template(contractTemplateRequest)
print(template['id'])
```
1 change: 0 additions & 1 deletion fireblocks_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from fireblocks_sdk.sdk import FireblocksSDK
from fireblocks_sdk.ncw_sdk import FireblocksNCW
from fireblocks_sdk.tokenization_sdk import FbTokenizationSDK
from fireblocks_sdk.sdk_token_provider import SdkTokenProvider
from fireblocks_sdk.api_types import *
from fireblocks_sdk.tokenization_api_types import *
59 changes: 59 additions & 0 deletions fireblocks_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
UnstakeRequestDto,
WithdrawRequestDto,
)
from .tokenization_api_types import \
CreateTokenRequest, \
ContractUploadRequest, \
ContractDeployRequest, \
ReadCallFunction, \
WriteCallFunction
from .sdk_token_provider import SdkTokenProvider


Expand Down Expand Up @@ -2688,6 +2694,59 @@ def get_smart_transfer_user_group_ids(self):
url = "/v1/smart-transfers/settings/user-groups"

return self._get_request(url)

def get_linked_tokens(self, limit: int = 100, offset: int = 0):
request_filter = {"limit": limit, "offset": offset}
return self._get_request("/v1/tokenization/tokens", query_params=request_filter)

def issue_new_token(self, request: CreateTokenRequest):
return self._post_request("/v1/tokenization/tokens", request.to_dict())

def get_linked_token(self, assetId: str):
return self._get_request(f"/v1/tokenization/tokens/{assetId}")

def link_token(self, assetId: str):
return self._put_request(f"/v1/tokenization/tokens/{assetId}/link", {})

def unlink_token(self, assetId: str):
return self._delete_request(f"/v1/tokenization/tokens/{assetId}")

def get_contract_templates(self, limit: int = 100, offset: int = 0):
request_filter = {
"limit": limit,
"offset": offset
}
return self._get_request("/v1/contract-registry/contracts", query_params=request_filter)

def upload_contract_template(self, request: ContractUploadRequest):
return self._post_request("/v1/contract-registry/contracts", request.to_dict())

def get_contract_template(self, contractId: str):
return self._get_request(f"/v1/contract-registry/contracts/{contractId}")

def get_contract_template_constructor(self, contractId: str, with_docs: bool=False):
return self._get_request(f"/v1/contract-registry/contracts/{contractId}/constructor?withDocs=${with_docs}")

def delete_contract_template(self, contractId: str):
return self._delete_request(f"/v1/contract-registry/contracts/{contractId}")

def deploy_contract(self, contractId: str, request: ContractDeployRequest):
return self._post_request(f"/v1/contract-registry/contracts/{contractId}/deploy", request.to_dict())

def get_contracts_by_filter(self, templateId: str, blockchainId: str = None):
return self._get_request(f"/v1/contract-service/contracts?templateId={templateId}&blockchainId={blockchainId}")

def get_contract_by_address(self, blockchainId: str, contractAddress: str):
return self._get_request(f"/v1/contract-service/contracts/{blockchainId}/{contractAddress}")

def get_contract_abi(self, blockchainId: str, contractAddress: str):
return self._get_request(f"/v1/contract-service/contracts/{blockchainId}/{contractAddress}/abi")

def read_contract_call_function(self, blockchainId: str, contractAddress: str, request: ReadCallFunction):
return self._post_request(f"/v1/contract-service/contracts/{blockchainId}/{contractAddress}/function/read", request.to_dict())

def write_contract_call_function(self, blockchainId: str, contractAddress: str, request: WriteCallFunction):
return self._post_request(f"/v1/contract-service/contracts/{blockchainId}/{contractAddress}/function/write", request.to_dict())

def _get_request(self, path, page_mode=False, query_params: Dict = None):
if query_params:
Expand Down
67 changes: 0 additions & 67 deletions fireblocks_sdk/tokenization_sdk.py

This file was deleted.

0 comments on commit f8cb28a

Please sign in to comment.