@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
or @turnkey/viem
signers.
Turnkey API documentation lives here: https://docs.turnkey.com.
Getting started
$ npm install @turnkey/http
import { ApiKeyStamper } from "@turnkey/api-key-stamper";
import { TurnkeyClient } from "@turnkey/http";
const stamper = new ApiKeyStamper({
apiPublicKey: "...",
apiPrivateKey: "...",
});
const client = new TurnkeyClient(
{
baseUrl: "https://api.turnkey.com",
},
stamper
);
const data = await TurnkeyApi.getWhoami({
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 private key-related signing endpoints, e.g. /submit/sign_transaction
, /submit/sign_raw_payload
). To help you simplify async mutations, @turnkey/http
provides a withAsyncPolling(...)
wrapper. Here's a quick example:
import { withAsyncPolling, TurnkeyActivityError } from "@turnkey/http";
const fetcher = withAsyncPolling({
request: client.createPrivateKeys,
});
try {
const activity = await fetcher({
body: {
},
});
console.log(
activity.result.createPrivateKeysResultV2?.privateKeys?.[0]?.privateKeyId
);
} catch (error) {
if (error instanceof TurnkeyActivityError) {
}
}
More examples
See createNewEthereumPrivateKey.ts
in the with-ethers
example.
See also