TypeScript: Transactions SDK

Interact with the blockchain using Transactions SDK

Overview

The DIMO Transactions SDK is an open-source TypeScript SDK built to facilitate developers in creating transactions. The objective of the Transactions SDK is to allow developer interactions with the DIMO vehicles and permissions on behalf of an end-user.

Transactions SDK on NPM Registry

Getting Started

To get started with the Transactions SDK, you should understand some of the terminologies.

Terms
What we mean

Batch Operations

Batch is the term used when multiple operations are included in one function call. Example: In the vehicle permission sharing function, use setVehiclePermissionsBatch to send requests for different vehicles with different permissions in one operation.

Bulk Operations

Bulk is the term used when multiple operations of the same kind are included in one function call. Example: In the vehicle permission sharing function, use setVehiclePermissionsBulk to send requests for different vehicles with the same permissions in one operation.

Mint

Mint simply means to create and publish (vehicles) onto the network. Do note that minting a vehicle does not mean the vehicle is connected to a data feed or earning rewards. Minting is the first step before connecting and earning. Example: In the mintVehicleWithDeviceDefinition function, developers can create a vehicle on behalf of the user with a provided vehicle definition.

Permissions

The access control on data types that the end user grants to developers. For details on permissions, refer to SACD.

SACD

Refers to permissions contract SACD.

Stampers

A signature provided by the user, in the SDK, this is the passkey that the user provides (face ID, fingerprint, etc).

Used in Account Abstraction (AA) models in ERC-4337, DIMO Global Accounts removes the dependencies on private keys and gas fees and allow the developers to initiate functions. DIMO utilizes Passkey Stamper to facilitate signing transactions on behalf of an end-user.

The user is in the driver's seat and full control over their own account but developers can perform actions when the user provides their passkey in an application.

Using the SDK

Installation

npm install @dimo-network/transactions

Import

import { PasskeyStamper } from "@turnkey/react-native-passkey-stamper";
import { KernelSigner, newKernelConfig, sacdPermissionValue } from '@dimo-network/transactions';

Initialization

// Set up the Signer configs
const kernelSignerConfig = newKernelConfig({
  rpcUrl: RPC_URL,
  bundlerUrl: BUNDLER_RPC,
  paymasterUrl: PAYMASTER_RPC,
  environment: 'dev', // omit to default to prod
});

// Initialize a new passkey stamper
const stamper = new PasskeyStamper({
  rpId: RPID,
});

// Initialize a new Signer session based on the Signer configs above
const kernelSigner = new KernelSigner(kernelSignerConfig);

// Pass the passkey received to initialize signer with user account infos	
await kernelSigner.passkeyInit(
  subOrganizationId,
  walletAddress as `0x${string}`,
  stamper,
);

// Optionally, set up the permissions
const permissions = sacdPermissionValue({
  ALLTIME_LOCATION: true,
});

// Optionally, set up the SACD agreement and upload to IPFS
const ipfsRes = await kernelSigner.signAndUploadSACDAgreement({
  driverID: grantee,
  appID: DIMO_APP_ID,
  appName: APP_NAME,
  expiration: expiration,
  permissions: permissions,
  tokenId: tokenId,
  grantee: grantee,
  attachments: [],
  grantor: kernelSigner.smartContractAddress!,
});

if (!ipfsRes.success) {
  throw new Error(
    `Unable to sign and upload SACD agreement: ${ipfsRes.error}`,
  );
}

Function Calls

const result = await kernelSigner.setVehiclePermissions({
  tokenId,
  grantee,
  permissions,
  expiration,
  source: `ipfs://${ipfsRes.data?.cid}`,
});

Contributions

(Contribution standards to be defined)

Last updated

Was this helpful?