You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@dfinity/agent

Package Overview
Dependencies
Maintainers
11
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/agent

JavaScript and TypeScript library to interact with the Internet Computer

3.2.0
latest
Source
npmnpm
Version published
Weekly downloads
391K
33.11%
Maintainers
11
Weekly downloads
 
Created

What is @dfinity/agent?

@dfinity/agent is a JavaScript library that allows developers to interact with the Internet Computer, a decentralized computing platform. It provides tools to create, manage, and communicate with canisters (smart contracts) on the Internet Computer.

What are @dfinity/agent's main functionalities?

Creating an HTTP Agent

This feature allows you to create an HTTP agent to communicate with the Internet Computer. The agent is configured with a host URL, which is the entry point to the network.

const { HttpAgent } = require('@dfinity/agent');
const agent = new HttpAgent({ host: 'https://ic0.app' });

Interacting with Canisters

This feature demonstrates how to interact with a canister using an actor. You define an interface for the canister and create an actor to call its methods, such as 'greet' in this example.

const { Actor, HttpAgent } = require('@dfinity/agent');
const agent = new HttpAgent();
const canisterId = 'your-canister-id';
const interfaceFactory = ({ IDL }) => IDL.Service({
  greet: IDL.Func([IDL.Text], [IDL.Text], []),
});
const actor = Actor.createActor(interfaceFactory, { agent, canisterId });
const response = await actor.greet('World');

Querying and Updating Canister State

This feature shows how to query and update the state of a canister. The 'getValue' method is a query call, while 'setValue' is an update call, demonstrating both read and write operations.

const { Actor, HttpAgent } = require('@dfinity/agent');
const agent = new HttpAgent();
const canisterId = 'your-canister-id';
const interfaceFactory = ({ IDL }) => IDL.Service({
  getValue: IDL.Func([], [IDL.Nat], ['query']),
  setValue: IDL.Func([IDL.Nat], [], []),
});
const actor = Actor.createActor(interfaceFactory, { agent, canisterId });
const currentValue = await actor.getValue();
await actor.setValue(currentValue + 1);

Other packages similar to @dfinity/agent

Keywords

internet computer

FAQs

Package last updated on 07 Aug 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.