@turnkey/http
A lower-level, fully typed HTTP client for interacting with Turnkey API.
For signing transactions and messages, check out the higher-level @turnkey/ethers
Signer.
API Docs: https://turnkey.readme.io/
Getting started
$ npm install @turnkey/http
Before making http calls, initialize the package with your credentials:
import { TurnkeyApi, init } from "@turnkey/http";
init({
apiPublicKey: "...",
apiPrivateKey: "...",
baseUrl: "...",
});
const data = await TurnkeyApi.postGetWhoami({
body: {
organizationId: "...",
},
});
HTTP fetchers
@turnkey/http
provides fully typed http fetchers for interacting with the Turnkey API. You can find all available methods here. The types of input parameters and output responses are also exported for convenience.
The OpenAPI spec that generates all fetchers is also included in the package.
withAsyncPolling(...)
helper
All Turnkey mutation endpoints are asynchronous (with the exception of signing endpoints). To help you simplify async mutations, @turnkey/http
provides a withAsyncPolling(...)
wrapper. Here's a quick example:
import {
TurnkeyApi,
withAsyncPolling,
TurnkeyActivityError,
} from "@turnkey/http";
const fetcher = withAsyncPolling({
request: TurnkeyApi.postCreatePrivateKeys,
});
try {
const activity = await fetcher({
body: {
},
});
console.log(activity.result.createPrivateKeysResult?.privateKeyIds?.[0]);
} catch (error) {
if (error instanceof TurnkeyActivityError) {
}
}
More examples
See createNewEthereumPrivateKey.ts
in the with-ethers
example.
See also