Skip to main content

onchainid.createIdentity(CreateIdentity)

Create (or fetch if already exists) an ONCHAINID identity for a given EOA (Externally Owned Account where the user controls the keys). If an identity is already associated with a subject, it returns that identity address with status: 'exists'.

CreateIdentity Type Parameters

ParameterTypeRequiredDescription
idFactoryAdminSignerRequiredID Factory Signer authorized to create identities.
subjectstringRequiredEOA of the identity the deployed ONCHAINID will be associated with.
deploymentSaltstringRequiredArbitrary string used for deterministic deployment.

Returns

FieldTypeDescription
statuscreated or exists'created' when a new identity was deployed, 'exists' if already present.
identitystringONCHAINID identity contract address that is bound to their EOA.
receiptTransactionReceiptTransaction receipt when created. Only present when status is 'created'.

Usage

TypeScript

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

async function main() {
    // 0. Create rwa_sdk 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. Get Admin wallet
    const admin = new Wallet(process.env.ADMIN_PRIVATE_KEY!, provider);

    // 2. Get Alice public address
    const alice = process.env.ALICE_PUBLIC_ADDRESS!

    // 3. Create ONCHAINID Identity params
    const createIdentity: CreateIdentity = {
        idFactoryAdmin: admin,
        subject: alice,
        deploymentSalt: "identity-" + Date.now().toString()
    }
    const result = await rwa_sdk.onchainid.createIdentity(createIdentity);
    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_sdk instance and get provider
    const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
    const rwa_sdk = new RWA({ chainId: Chain.AGUNG, provider: provider });
  
    // 1. Get Admin wallet
    const admin = new Wallet(process.env.ADMIN_PRIVATE_KEY, provider);

    // 2. Get Alice public address
    const alice = process.env.ALICE_PUBLIC_ADDRESS

    // 3. Create ONCHAINID Identity
    const result = await rwa_sdk.onchainid.createIdentity({
        idFactoryAdmin: admin,
        subject: alice,
        deploymentSalt: "identity-" + Date.now().toString()
    });
    console.log("Result", result);
}

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

Example outputs

Created:
Result {
  status: 'created',
  identity: '0x1e747251c5F1A4cDC4CD667536db2949A93aB110',
  receipt: ContractTransactionReceipt {
    ...
  }
}
Already exists:
Result {
  status: 'exists',
  identity: '0x1e747251c5F1A4cDC4CD667536db2949A93aB110'
}