Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
@tango-crypto/tangocrypto-js
Advanced tools
Javascript client for tangocrypto API
Weekly downloads
Readme
TypeScript/JavaScript sdk for Tangocrypto platform.
Go to tangocrypto.com, login/register, then create an app and save your apiKey
and appId
.
In the dashboard go to your app details and copy the value for APP Id and API Key.
This library is intended to be use on Node.js
npm i @tango-crypto/tangocrypto-js
Using the SDK is pretty simple as you can see from the following examples. You just need to create an Tangocrypto
instance.
import { Tangocrypto, Network } from '@tango-crypto/tangocrypto-js';
// or CommonJS
// const { Tangocrypto, Network } = require('@tango-crypto/tangocrypto-js');
const client = new Tangocrypto({
apiKey: process.env.API_KEY, // your account id
appId: process.env.APP_ID, // your app id
network: Network.CARDANO_MAINNET, // Network to determine the base URL, default to https://cardano-mainnet.tangocrypto.com
version: process.env.VERSION, // API version, default to v1
maxAttempts: 5 // maximmum retry attemps when request fails and is retryable (e.g. status 429)
})
apiKey
: Your account Id (required).appId
: Your app Id.network
: Network to determine the base URL, default to https://cardano-mainnet.tangocrypto.com
version
: String for API version, default to v1
.maxAttempts
: Number indicating the maximmum retry attemps when request fails and is retryable (e.g. status 429).For more examples take a look in examples directory.
After you have created a Tangocrypto
instance you have different API instances to interact with the backend.
Addresses
: Get access to a set of endpoints cardano address related.Assets
: Get access to a set of endpoints cardano asset related.Blocks
: Get access to a set of endpoints cardano block related.Epochs
: Get access to a set of endpoints cardano epoch related.Policies
: Get access to a set of endpoints cardano policy related.Pools
: Get access to a set of endpoints cardano pool related.Transactions
: Get access to a set of endpoints cardano transaction related.Wallets
: Get access to a set of endpoints cardano stake address related.Webhooks
: Get access Webhooks API.Nfts
: Get access to NFT Studio API.Ipfs
: Get access to Ipfs API.All API instances methods return an instance of TangocryptoResponse<T>
definde this way:
export interface TangocryptoResponse<T> {
result: T;
$metadata: Metadata;
}
Where T
corresponding to the data specific for each endpoint. More info about each endpoint request/response here. The field $metadata
contains the attemps
and totalRetryDelay
were needed in order to perform the request. If the request was success in the first call $metadata
will look like this:
{ attempts: 1, totalRetryDelay: 0 }
The errors throws by this sdk are instances of TangocryptoError
with the same structure you get from the API.
{
"status_code": 404,
"message": "epoch: 63 not found",
"error": "Not Found"
}
Check here for all possible status_code
and meaning.
TancryptoError
extends built-in Error
class, so you can catch it in your code and perform custom logic.
const api = new Tangocrypto({
apiKey: process.env.API_KEY,
appId: process.env.APP_ID,
network: Network.CARDANO_TESTNET,
version: process.env.VERSION
}).block()
// missing block number
const block = -1;
try {
const response = await api.getBlock(block);
} catch (err) {
if (err instanceof TangocryptoError) {
// missing block number
console.log(err.toString()); // TangocryptoError: {"status_code":404,"message":"block number: -1 not found","error":"Not Found"}
} else {
// other errors
throw err;
}
}
Getting latest block in the blockchain
const api = client.block(); // get block API client instance
const response = await api.getLatestBlock();
console.log(response.result);
Output:
>> {
"hash": "7135250e403466c2163c6ba3aa8606f4dd6396e282c512486740aeaa220fbaf9",
"epoch_no": 229,
"slot_no": 68672434,
"epoch_slot_no": 114034,
"block_no": 3832866,
"previous_block": 3832865,
"slot_leader": "pool1l8kt8vn966ylkgysaj28ut34qu8z7nrjxyjj3n77v9ae6clyjfp",
"confirmations": 1,
"size": 4,
"time": "2022-09-13T04:00:50.000Z",
"tx_count": 0,
"vrf_key": "vrf_vk1cxcf73rmj7luakn0ykjtvsf3mzqj5akhh3j82hamch4srlvx37tsy2gg35",
"op_cert": "48a680a489fbf4d0035afec3596e42eb05c2d2d3ebfa4ca5f6210ddb74d7facc"
}
Access to IPFS
const api = new Tangocrypto({
apiKey: process.env.API_KEY,
}).ipfs()
const { result } = await api.listContents();
console.log(result.data);
Output:
>>> [{
"created_at": "2022-12-19T18:01:33.326Z",
"status": "pinned",
"account_id": "8120536a5efc478b92809f8f1987a76e",
"name": "test-tangocrypto-js",
"updated_at": "2022-12-19T18:01:33.326Z",
"content_cid": "bafybeicfu52l2qhibv6juzeks7tjjnbzv7ykqusgcjlokg3i3aecn4ttsy",
"id": "01gmnrrkce3ggjwc11t15e5zb8",
"cid": "QmT2YwTAj9T3umZ7CRFW94vRg58dWUnYCyc8s8LdXn3KWV",
"pins": [
{
"location": {
"ipfs_peer_id": "12D3KooWEfdXu9Ssk8abzxaB5fVPyY9ojFaU3EgSzzjEcEfBfFDe",
"peer_id": "12D3KooWCLuHQj5ZyvE3VRBAPazAfmAn2pz3CkK14YdvWrhuyszg",
"peer_name": "cluster0"
},
"id": "12D3KooWCLuHQj5ZyvE3VRBAPazAfmAn2pz3CkK14YdvWrhuyszg",
"status": "Pinned"
}
],
"dag_size": 244927,
"type": "Upload"
},
...
]
Please check our docs for more information about all the tangocrypto features.
FAQs
Javascript client for tangocrypto API
The npm package @tango-crypto/tangocrypto-js receives a total of 1 weekly downloads. As such, @tango-crypto/tangocrypto-js popularity was classified as not popular.
We found that @tango-crypto/tangocrypto-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.