3.16.0 • Published 3 months ago

@slide-computer/signer-agent v3.16.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@slide-computer/signer-agent

Initiate transactions with signers on the Internet Computer.


Installation

Using SignerAgent:

npm i --save @slide-computer/signer-agent

In the browser:

import { SignerAgent } from "@slide-computer/signer-agent";

To get started with the signerAgent, run

const accounts = await signer.accounts();
const agent = await SignerAgent.create({
    signer,
    account: accounts[0].owner
});

The signerAgent can initiate a transaction with

import {IcrcLedgerCanister} from "@dfinity/ledger-icrc";

const icpLedger = IcrcLedgerCanister.create({
    agent,
    canisterId: ICP_LEDGER_CANISTER_ID,
});
const blockIndex = await icpLedger.transfer({
    to: TARGET_ACCOUNT,
    amount: 100_000_000
});

The signerAgent can automatically batch calls with

import {IcrcLedgerCanister} from "@dfinity/ledger-icrc";

const icpLedger = IcrcLedgerCanister.create({
    agent,
    canisterId: ICP_LEDGER_CANISTER_ID,
});
const ckBtcLedger = IcrcLedgerCanister.create({
    agent,
    canisterId: CK_BTC_LEDGER_CANISTER_ID,
});

// If a signer does not support batch calls, signerAgent will 
// automatically fallback to executing the calls one by one.
const [icpBlockIndex, ckBtcBlockIndex] = await Promise.all([
    icpLedger.approve({
        spender: TARGET_ACCOUNT,
        amount: 70_000_000
    }),
    ckBtcLedger.approve({
        spender: TARGET_ACCOUNT,
        amount: 1_000_000
    })
]);

For more advanced use cases, the signerAgent can also manually batch calls with

import {IcrcLedgerCanister} from "@dfinity/ledger-icrc";

const icpLedger = IcrcLedgerCanister.create({
    agent,
    canisterId: ICP_LEDGER_CANISTER_ID,
});
const ckBtcLedger = IcrcLedgerCanister.create({
    agent,
    canisterId: CK_BTC_LEDGER_CANISTER_ID,
});

agent.batch(); // Below execution of calls needs to be triggered manually

const icpBlockIndexPromise = icpLedger.approve({
    spender: TARGET_ACCOUNT,
    amount: 70_000_000
});
const ckBtcBlockIndexPromise = ckBtcLedger.approve({
    spender: TARGET_ACCOUNT,
    amount: 1_000_000
});

agent.batch() // Indicate that below calls should be executed by the signer after the above

const swapResultPromise = backendActor.swapTokens(swapId);

// Trigger execution of all the above scheduled calls
// 
// If a signer does not support batch calls, signerAgent will 
// automatically fallback to executing the calls one by one.
await agent.execute();

// Get individual results
const icpBlockIndex = await icpBlockIndexPromise;
const ckBtcBlockIndex = await ckBtcBlockIndexPromise;
const swapResult = await swapResultPromise;
3.15.0

3 months ago

3.14.0

4 months ago

3.16.0

3 months ago

3.9.0

6 months ago

3.8.1

6 months ago

3.7.2

6 months ago

3.11.0

6 months ago

3.10.1

6 months ago

3.8.0

6 months ago

3.7.1

6 months ago

3.10.0

6 months ago

3.7.0

7 months ago

3.13.0

4 months ago

3.10.3

6 months ago

3.12.0

4 months ago

3.10.2

6 months ago

1.9.0

1 year ago

2.2.0

12 months ago

2.4.0

12 months ago

2.6.1

12 months ago

2.6.0

12 months ago

2.5.4

12 months ago

2.6.2

12 months ago

3.6.4

9 months ago

3.6.3

9 months ago

2.1.0

12 months ago

2.0.1

12 months ago

2.0.0

12 months ago

3.4.0

10 months ago

3.3.0

10 months ago

3.2.0

10 months ago

3.1.0

10 months ago

3.6.2

9 months ago

3.6.1

10 months ago

3.6.0

10 months ago

3.5.0

10 months ago

3.0.0

10 months ago

1.8.0

1 year ago

1.7.0

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago