
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
@keypom/trial-accounts
Advanced tools
Core library for interacting with and creating Multichain Trial Accounts
The Keypom Multichain Trial Accounts SDK provides a seamless way to create and manage trial accounts across multiple blockchain networks, including NEAR and EVM-compatible chains. This SDK abstracts the complexities involved in setting up trial accounts, managing their constraints, and performing actions on their behalf. With this package, you can:
To install the Keypom Multichain Trial Accounts SDK, run one of the following commands:
npm install @keypom/trial-accounts
# or
yarn add @keypom/trial-accounts
# or
pnpm add @keypom/trial-accounts
Before using the SDK, you need to initialize the TrialAccountManager
class. This class provides methods to manage trial accounts and interact with the trial contract.
import { TrialAccountManager } from "@keypom/trial-accounts";
import { Near, Account } from "@near-js/wallet-account";
import { UnencryptedFileSystemKeyStore } from "@near-js/keystores-node";
import path from "path";
import os from "os";
// Set up NEAR connection
const homedir = os.homedir();
const credentialsPath = path.join(homedir, ".near-credentials");
const keyStore = new UnencryptedFileSystemKeyStore(credentialsPath);
const near = new Near({
networkId: "testnet",
keyStore,
nodeUrl: "https://rpc.testnet.near.org",
});
const signerAccount = await near.account("your-account.testnet");
const trialManager = new TrialAccountManager({
trialContractId: "trial-contract.your-account.testnet",
mpcContractId: "v1.signer-prod.testnet",
signerAccount,
near,
});
trialContractId
: The account ID where the trial contract is deployed.mpcContractId
: The account ID of the MPC contract.signerAccount
: An instance of Account
used for signing transactions.near
: The NEAR connection instance.Create a new trial with specific constraints per chain. For example, you can set different allowed methods and contracts for NEAR and EVM chains.
import { TrialData } from "@keypom/trial-accounts";
import { parseEther } from "ethers";
import { parseNearAmount } from "@near-js/utils";
const trialData: TrialData = {
constraintsByChainId: {
EVM: {
chainId: 84532,
allowedMethods: ["setMessage"],
allowedContracts: ["0xdf5c3bd628a11C97BB25d441D8b6d9Ce974dc552"],
maxGas: 1000000,
maxValue: "0",
initialDeposit: parseEther("0.004"), // approximately $15 worth of ETH
},
NEAR: {
allowedMethods: ["add_message"],
allowedContracts: ["guestbook.near-examples.testnet"],
maxGas: null,
maxDeposit: null,
initialDeposit: parseNearAmount("10")!, // 10 NEAR tokens
},
},
usageConstraints: null,
interactionLimits: null,
exitConditions: null,
expirationTime: null,
};
// Create the trial
const trialId = await trialManager.createTrial(trialData);
console.log(`Trial created with ID: ${trialId}`);
Add trial accounts to the trial by generating limited access keys and then activate them.
// Add trial accounts
const numberOfKeys = 1;
const trialKeys = await trialManager.addTrialAccounts(numberOfKeys);
console.log(`Added ${trialKeys.length} trial account(s).`);
// Activate the trial account for a specific chain (e.g., NEAR or EVM)
const trialKey = trialKeys[0];
const chainId = "NEAR"; // or "84532" for EVM chain
const accountId = `trial-account-${Date.now()}.testnet`;
trialManager.setTrialAccountCredentials(
accountId,
trialKey.trialAccountSecretKey
);
await trialManager.activateTrialAccounts(accountId, chainId);
console.log(`Trial account ${accountId} activated.`);
Perform actions on behalf of the trial account, such as calling methods on contracts. The SDK ensures that the actions are within the specified constraints.
import { ActionToPerform } from "@keypom/trial-accounts";
import { BASE_GUESTBOOK_ABI } from "./abis/baseGuestbook";
// Define the action to perform on the EVM chain
const action: ActionToPerform = {
chain: "EVM",
chainId: 84532, // Base Sepolia chain ID
targetContractId: "0xdf5c3bd628a11C97BB25d441D8b6d9Ce974dc552",
methodName: "setMessage",
args: ["Hello from the trial account!"],
abi: BASE_GUESTBOOK_ABI,
value: "0",
accessList: [],
};
// Request signature and perform the action
const providerUrl = `https://base-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY`;
const { signatures, txnDatas } = await trialManager.performActions(
[action],
providerUrl
);
// Broadcast the transaction
const { result } = await trialManager.broadcastTransaction({
actionToPerform: action,
signatureResult: signatures[0],
signerAccountId: accountId,
providerUrl,
txnData: txnDatas[0],
});
console.log("Action performed successfully.");
You can customize various settings, such as retry logic and configurations for different chains.
// Set custom retry logic
trialManager.setRetryConfig({
maxRetries: 5,
initialDelayMs: 2000,
backoffFactor: 2,
});
// Set trial account credentials if needed
trialManager.setTrialAccountCredentials("trial-account.testnet", "ed25519:...");
// Set trial ID
trialManager.setTrialId(123);
maxRetries
: Maximum number of retries for operations.initialDelayMs
: Initial delay before retrying (in milliseconds).backoffFactor
: Exponential backoff factor.The package includes several scripts to automate common tasks. You can run these scripts using commands defined in the package.json.
pnpm run deploy:evm
pnpm run deploy:near
pnpm run deploy:omni
These scripts correspond to configurations defined in the configs directory:
Ensure Environment Variables are Set: Create a .env file in the root directory with the necessary environment variables, especially for EVM interactions.
EVM_PRIVATE_KEY=your_evm_private_key
ALCHEMY_API_KEY=your_alchemy_api_key
Install Dependencies:
pnpm install
Run the scripts:
pnpm run deploy:evm
pnpm run deploy:near
pnpm run deploy:omni
The script will:
Trial accounts are temporary accounts with limited access, ideal for onboarding new users or running promotions. They use limited access keys to ensure they operate within specified constraints.
The SDK integrates with a Multi-Party Computation (MPC) service to securely sign transactions without exposing private keys.
When creating a trial, you can specify various constraints to control how trial accounts interact with the blockchain.
Example:
const trialData: TrialData = {
constraintsByChainId: {
EVM: {
chainId: 84532,
allowedMethods: ["setMessage"],
allowedContracts: ["0xdf5c3bd628a11C97BB25d441D8b6d9Ce974dc552"],
maxGas: 1000000,
maxValue: "0",
initialDeposit: parseEther("0.004"),
},
},
usageConstraints: null,
interactionLimits: null,
exitConditions: null,
expirationTime: null,
};
We welcome contributions to the Keypom Trial Accounts SDK! Please follow these guidelines:
This project is licensed under the GPL License.
Thank you for using the Keypom Trial Accounts SDK! If you have any questions or need assistance, feel free to join our community or open an issue on GitHub.
FAQs
Core library for interacting with and creating Multichain Trial Accounts
The npm package @keypom/trial-accounts receives a total of 6 weekly downloads. As such, @keypom/trial-accounts popularity was classified as not popular.
We found that @keypom/trial-accounts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.