You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{createKeyringPair}from'@propchain/sdk';// Development account (use browser extension in production)constalice=createKeyringPair('//Alice');const{ propertyId, txHash }=awaitclient.propertyRegistry.registerProperty(alice,{location: '123 Main St, New York, NY',size: 2500,legalDescription: 'Lot 1, Block 2, City Subdivision',valuation: BigInt('50000000000000'),// $500,000 with 8 decimalsdocumentsUrl: 'ipfs://QmXoypizj...',},);console.log(`Property ${propertyId} registered in tx ${txHash}`);
import{connectExtension,getExtensionSigner}from'@propchain/sdk';functionConnectWallet(){consthandleConnect=async()=>{constaccounts=awaitconnectExtension('My PropChain dApp');constsigner=awaitgetExtensionSigner(accounts[0].address);// Use signer for transactions};return<buttononClick={handleConnect}>Connect Wallet</button>;}
Context Provider Pattern
import{createContext,useContext,ReactNode}from'react';import{PropChainClient}from'@propchain/sdk';constPropChainContext=createContext<PropChainClient|null>(null);exportfunctionPropChainProvider({
children,
wsEndpoint,
addresses,}: {children: ReactNode;wsEndpoint: string;addresses: ContractAddresses;}){constclient=usePropChain(wsEndpoint,addresses);return(<PropChainContext.Providervalue={client}>{children}</PropChainContext.Provider>);}exportfunctionusePropChainClient(){constclient=useContext(PropChainContext);if(!client)thrownewError('Must be used within PropChainProvider');returnclient;}
// Type-safe event subscriptionconstsub=awaitclient.propertyRegistry.on('PropertyRegistered',(event)=>{// event is typed as PropertyRegisteredEventconsole.log('ID:',event.propertyId);console.log('Owner:',event.owner);console.log('Location:',event.location);});
import{PropChainError,getUserFriendlyMessage}from'@propchain/sdk';try{awaitclient.propertyRegistry.transferProperty(signer,999,recipient);}catch(error){if(errorinstanceofPropChainError){console.log('Category:',error.category);// 'PropertyRegistry'console.log('Variant:',error.variant);// 'PropertyNotFound'console.log('Description:',error.description);// 'Property does not exist...'// Display to usershowToast(getUserFriendlyMessage(error));}}
import{NETWORKS,connectToNetwork}from'@propchain/sdk';// Use built-in presetsconstapi=awaitconnectToNetwork('westend');// Or access preset configsconsole.log(NETWORKS.local.wsEndpoint);// 'ws://127.0.0.1:9944'
cd sdk/frontend
# Run all tests
npm test# Watch mode
npx vitest
# Coverage report
npm run test:coverage
Writing Tests for Your dApp
import{describe,it,expect,vi}from'vitest';// Mock the SDKvi.mock('@propchain/sdk',()=>({PropChainClient: {create: vi.fn().mockResolvedValue({propertyRegistry: {getProperty: vi.fn().mockResolvedValue({id: 1,owner: '5Grw...',metadata: {location: 'Test',size: 100,valuation: BigInt(100000)},}),},}),},}));describe('My Property Component',()=>{it('displays property data',async()=>{// Test your component using the mocked SDK});});
Integration Tests (with Local Node)
# 1. Start node
docker-compose up -d
# 2. Deploy contracts
./scripts/deploy.sh --network local# 3. Set contract addressesexport REGISTRY_ADDRESS=5Grw...
export TOKEN_ADDRESS=5FHn...
# 4. Run integration testscd sdk/frontend
npx vitest run __tests__/integration.test.ts
Troubleshooting
Common Issues
Problem
Solution
ConnectionError: Failed to connect
Ensure Substrate node is running on the correct port
PropChainError: ContractPaused
The contract is paused — contact admin or wait for resume