Skip to main content

mnft.registerMachine(RegisterMachine)

Register one or more Machine NFTs to a designated controller. This sends transactions from the Machine Issuer and charges the ERC20 fee from the controller. The Machine NFT must be funded prior to execution.

RegisterMachine Type Parameters

ParameterTypeRequiredDescription
machineIssuerSignerRequiredMachine Issuer signer that submits the mint transactions. Must be connected to a provider.
machineNftstringRequiredMachine NFT contract address.
machineValueHumanstringRequiredMachine value in human-readable units (e.g., "10").
machineControllerAddrstringRequiredEOA address that will control/own the machines.
erc20stringRequiredERC20 token address used to pay the fee.
tokenDecimalsnumberRequiredERC20 token decimals.
saltnumberRequiredSalt used to derive the DID document.
countnumberRequiredNumber of machines to register.

Returns

FieldTypeDescription
statusissuedStatus of the operation.
machineNftstringMachine NFT contract address.
machineIssuerstringMachine Issuer address that submitted the transaction(s).
machineControllerstringMachine controller/owner address.
machineValue{ human: string; units: bigint; tokenDecimals: number; feeToken: string }Machine value details.
countnumberNumber of machines issued.
machines{ machineId: string; did?: string; receipt?: TransactionReceipt }[]Per-machine results and receipts.
feesPaidbigintERC20 fees paid by the controller.
startingBalancebigintController ERC20 balance before issuance.
endingBalancebigintController ERC20 balance after issuance.
humanTokenDeltastringHuman-readable fee delta.

Usage

TypeScript

import 'dotenv/config';
import { RWA, Chain, type SDKInit } from "@peaq-network/rwa";
import { JsonRpcProvider, Wallet } from "ethers";

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const init: SDKInit = { chainId: Chain.AGUNG, provider: provider };
  const rwa_sdk = new RWA(init);

  // 1. Machine Issuer wallet
  const machineIssuer = new Wallet(process.env.MACHINE_ISSUER_PRIVATE_KEY!, provider);

  // 2. Machine controller (receives NFT and pays ERC20 fee via allowance)
  const alice = process.env.ALICE_PUBLIC_ADDRESS!;


  // 3. Register MachineNFT(s) for Alice
  const result = await rwa_sdk.mnft.registerMachine({
    machineIssuer: machineIssuer,
    machineNft: "0x5Ca3db1f292f913DDdA8C5385E5391438665463c",
    machineValueHuman: "10",
    machineControllerAddr: alice,
    erc20: rwa_sdk.getAddresses().erc20.peaq,
    tokenDecimals: 18,
    salt: Math.floor(Math.random() * 10000),
    count: 2
  });

  console.log('Result', result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

JavaScript

import 'dotenv/config';
import { RWA, Chain } from "@peaq-network/rwa";
import { JsonRpcProvider, Wallet } from "ethers";

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const rwa_sdk = new RWA({ chainId: Chain.AGUNG, provider });

  // 1. Machine Issuer wallet
  const machineIssuer = new Wallet(process.env.MACHINE_ISSUER_PRIVATE_KEY, provider);

  // 2. Machine controller (receives NFT and pays ERC20 fee via allowance)
  const alice = process.env.ALICE_PUBLIC_ADDRESS;

  // 3. Register MachineNFT(s) for Alice
  const result = await rwa_sdk.mnft.registerMachine({
    machineIssuer: machineIssuer,
    machineNft: "0x5Ca3db1f292f913DDdA8C5385E5391438665463c",
    machineValueHuman: "10",
    machineControllerAddr: alice,
    erc20: rwa_sdk.getAddresses().erc20.peaq,
    tokenDecimals: 18,
    salt: Math.floor(Math.random() * 10000),
    count: 2
  });

  console.log('Result', result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Example outputs

Result {
  status: 'issued',
  machineNft: '0x5Ca3db1f292f913DDdA8C5385E5391438665463c',
  machineIssuer: '0x8BCfa2e9FC4aCa66fCF36Bcf47646E5Fb8d74BA0',
  machineController: '0x16cd4D21537eD8F33bE08271A9FA6DCC426709b2',
  machineValue: {
    human: '10',
    units: 10000000000000000000n,
    tokenDecimals: 18,
    feeToken: '0x...'
  },
  count: 2,
  machines: [
    { machineId: '1', did: 'did:peaq:...', receipt: ContractTransactionReceipt { ... } },
    { machineId: '2', did: 'did:peaq:...', receipt: ContractTransactionReceipt { ... } }
  ],
  feesPaid: 20000000000000000000n,
  startingBalance: 100000000000000000000n,
  endingBalance: 80000000000000000000n,
  humanTokenDelta: '20.0'
}