AccessTime SDK
The AccessTime SDK provides an easy-to-use TypeScript package for interacting with AccessTime smart contracts. It simplifies contract interactions by handling view configurations, event listeners, and transaction calls.
Installation
npm install @accesstimeio/accesstime-sdk
AccessTime Configuration
To use the SDK, you need to provide some configurations:
accessTime
: The deployed AccessTime contract address.chain
: The blockchain network configuration.chain.id
: The blockchain network id.chain.rpcUrl
: The blockchain network url, optional.
Examples
Creating a client
import { AccessTime } from "@accesstimeio/accesstime-sdk";
const accessTime = new AccessTime({
accessTime: "0xAccessTimeAddress",
chain: {
id: 8453,
}
});
Read call
import { AccessTime } from "@accesstimeio/accesstime-sdk";
const accessTime = new AccessTime({
accessTime: "0xAccessTimeAddress",
chain: {
id: 8453,
}
});
const userAddress = "0xUserAddress";
const userAccessTimeEnd = await accessTime.read.accessTimes([userAddress]);
Event listening
import { AccessTime } from "@accesstimeio/accesstime-sdk";
const accessTime = new AccessTime({
accessTime: "0xAccessTimeAddress",
chain: {
id: 8453,
}
});
const purchaseEvent = accessTime.watchEvent.Purchased({
user: undefined, // filter by user
amount: undefined, // filter by amount
paymentToken: undefined // filter by paymentToken
}, {
onLogs: (events) => {
for (const _event of events) {
console.log("Purchased.event", _event);
// event handling
}
}
});
purchaseEvent(); // unwatch call
Write, Simulate calls
import { privateKeyToAccount } from "viem/accounts";
import { AccessTime } from "@accesstimeio/accesstime-sdk";
const accessTime = new AccessTime({
accessTime: "0xAccessTimeAddress",
chain: {
id: 8453,
}
});
const account = privateKeyToAccount("0xAccountPrivateKey");
const chain = accessTime.publicClient.chain;
try {
await accessTime.simulate.withdrawEther({
account,
chain
});
const transactionHash = await accessTime.write.withdrawEther({
account,
chain
});
console.log("withdrawEther.transactionHash", transactionHash);
} catch (err) {
console.error("withdrawEther.call", "Failed!");
console.error("withdrawEther.error", err);
}
AccessTimeFactory Configuration
To use the SDK, you need to provide some configurations:
id
: The blockchain network id.rpcUrl
: The blockchain network url, optional.
Examples
Creating a client
import { Factory } from "@accesstimeio/accesstime-sdk"
const factory = new Factory({
id: 8453
});
Read call
import { Factory } from "@accesstimeio/accesstime-sdk"
const factory = new Factory({
id: 8453
});
const accessTimeAddress = "0xAccessTimeAddress";
const accessTimeDetails = await factory.read.deploymentDetails([accessTimeAddress]);
Event listening
import { Factory } from "@accesstimeio/accesstime-sdk"
const factory = new Factory({
id: 8453
});
const deployEvent = factory.watchEvent.Deployed({
user: undefined // filter by user
}, {
onLogs: (events) => {
for (const _event of events) {
// event handling
}
}
});
deployEvent(); // unwatch call
Write, Simulate calls
import { privateKeyToAccount } from "viem/accounts";
import { Factory } from "@accesstimeio/accesstime-sdk"
const factory = new Factory({
id: 8453
});
const account = privateKeyToAccount("0xAccountPrivateKey");
const chain = factory.publicClient.chain;
const deployArgs = [
0n, // paymentAmount, if ether(zero address) selected this should be zero and pass amount as value
// otherwise need to write required token amount
"0xTokenAddress", // paymentToken, zero address (ether) or token address
true, // activateExtraTime, can toggle-able later
true, // activatePackageModule, can toggle-able later
["project name", "project description", "project website"] // project details
] as const;
try {
await factory.simulate.deploy(deployArgs, {
value: 0n, // if ether(zero address) selected this should be paymentAmount
account,
chain
});
const transactionHash = await factory.write.deploy(deployArgs, {
value: 0n, // if ether(zero address) selected this should be paymentAmount
account,
chain
});
console.log("deploy.transactionHash", transactionHash);
} catch (_err) {
console.error("deploy.call", "Failed!");
}
Features
- Provides full ABIs for AccessTime contracts.
- Supports read calls and event listeners.
- Enables write calls (requires a connected account).
This SDK helps developers interact with AccessTime contracts without handling raw contract interactions manually.