You are ready to get started! Below is the basic flow for setting up an RWA Client and minting new tokens using Medici.
Install Package
Step 1: Install Medici
yarnadd@bridgesplit/rwa-token-sdk
Initialize RWA Client
Step 2: Begin by importing the RWA client, and instantiating it with its respective parameters.
constconnectionUrl=process.env.RPC_URL??'http://localhost:8899';constconnection=newConnection(connectionUrl);constconfirmationOptions:ConfirmOptions= { skipPreflight:false, maxRetries:3, commitment:'processed'}constconfig:Config= { connection: connection, rpcUrl: connectionUrl, confirmationOptions: confirmationOptions}/* Setup: payerKp, is just the keypair who will pay for the tx. */constrwaClient=newRwaClient(config,newWallet(setup.payerKp))
Initialize an Asset Controller
Step 3: Initialize an asset controller on chain.
constSetupAssetControllerArgs= { decimals,/* Token decimals */ payer:setup.payer.toString(),/* The wallet who will pay */ authority:setup.authority.toString(),/* Token decimals */ name:'Test Class Asset', uri:'https://test.com', symbol:'TFT'/* You can always update name, uri, symbol later via rwaClient.dataRegistry.updateAssetsDataAccountInfoIxns() */};constsetupIx=awaitrwaClient.assetController.setupNewRegistry(SetupAssetControllerArgs)consttxnId=awaitsendAndConfirmTransaction(rwaClient.provider.connection,newTransaction().add(...setupIx.ixs), [setup.payerKp,...setupIx.signers]);constmint=setupIx.signers[0].publicKey.toString(); /* Make sure to record assets mint */
Setup Data Registry
Step 4: Create the data registry account.
constcreateDataAccountArgs:CreateDataAccountArgs= { type: { legal: {} },/* This is where your record of legal documentation will go */ name:"Test Data Account", uri:"https://test.com", payer:setup.payer.toString(), assetMint: mint, };/* Note: you can update the data registry later with rwaClient.dataRegistry.updateAssetsDataAccountInfoIxns() */constcreateDataAccountIx=awaitrwaClient.dataRegistry.setupDataAccount( createDataAccountArgs);consttxnId=awaitsendAndConfirmTransaction(rwaClient.provider.connection,newTransaction().add(...createDataAccountIx.ixs), [setup.payerKp,createDataAccountIx.signers[0]]);constdataAccount=createDataAccountIx.signers[0].publicKey.toString();
Attach a Policy
Step 5: Use the policy engine to attach policies to the asset.
constpolicyArgs:AttachPolicyArgs= { authority:setup.authority.toString(), owner:setup.authority.toString(), assetMint: mint, payer:setup.payer.toString(),/* Identity filter is used for group specific policies */ identityFilter: { identityLevels: [1], comparisionType: { or: {} }, }, policyType: { identityApproval: {},/* The following are example policy's you can pass instead of identity approval: transactionAmountLimit: { limit: new BN(100), } transactionAmountVelocity: { limit: new BN(100000) timeframe: new BN(60) } transactionCountVelocity: { limit: new BN(100), timeframe: new BN(60), } ,*/ },};constpolicyIx=awaitrwaClient.policyEngine.attachPolicy(policyArgs)consttxnId=awaitsendAndConfirmTransaction(rwaClient.provider.connection,newTransaction().add(...policyIx.ixs), [setup.payerKp,...policyIx.signers]);/* Extra accounts that are sent in txns, not defined in the anchor idl */remainingAccounts.push(policyIx.signers[0].publicKey.toString());
Setup the First User
Step 6: Setup the first user (developer wallet). This user will hold all the issuance tokens.