DeFarm SDK - Git for traceability with multi-role permissions and global item discovery for agriculture supply chain
npm install defarm-sdkComplete blockchain infrastructure for agricultural supply chain management
The DeFarm SDK Enterprise is a comprehensive solution that combines on-premise data processing, blockchain tokenization, and cloud services in a flexible, enterprise-ready package.
``bash`
npm install @defarm/sdk
`bashGet your API key at https://defarm.io/dashboard
export DEFARM_API_KEY="sk_live_your_api_key_here"
Deployment Modes
$3
Complete data isolation with no cloud dependencies:`javascript
const { DeFarmSDK } = require('@defarm/sdk');const sdk = new DeFarmSDK({
deploymentMode: 'on-premise',
database: {
type: 'postgresql',
host: 'localhost',
database: 'defarm_local'
},
blockchain: {
enabled: false // Optional blockchain
}
});
await sdk.initialize();
`$3
Full cloud integration with gas-free transactions:`javascript
const sdk = new DeFarmSDK({
deploymentMode: 'cloud',
relay: {
enabled: true,
apiKey: 'YOUR_API_KEY'
},
enterprise: {
premiumAPI: true,
servicesEnabled: true
}
});
`$3
Best of both worlds - local processing with cloud enhancements:`javascript
const sdk = new DeFarmSDK({
deploymentMode: 'hybrid',
database: {
type: 'oracle', // Local enterprise DB
host: 'internal.company.com'
},
relay: {
enabled: true // Gas-free blockchain
},
enterprise: {
premiumAPI: true // Cloud analytics
}
});
`Usage Examples
$3
`javascript
// Process with WASM protection
const result = await sdk.processAgricultureData({
type: 'livestock',
breed: 'Angus',
weight: 450,
location: 'Farm A',
health_status: 'healthy'
});
`$3
`javascript
// Initialize with API key
const sdk = new DeFarmSDK({
apiKey: process.env.DEFARM_API_KEY, // Required for tokenization
deploymentMode: 'hybrid'
});// Check usage limits
const usage = await sdk.getUsage();
console.log(
Tokenizations used: ${usage.usage.tokenizations.used}/${usage.usage.tokenizations.limit});
`$3
`javascript
// No private keys needed - DeFarm sponsors the transaction
const token = await sdk.createAssetToken(
{
asset_type: 'cattle',
quantity: 100,
location: 'Brazil',
certifications: ['organic', 'grass-fed']
},
{
clientWallet: 'GCLIENT...XYZ' // Just the public address
}
);console.log('Token created:', token.tokenId);
console.log('Transaction:', token.explorerUrl);
console.log('Gas paid by DeFarm:', token.gasCost);
`$3
`javascript
// Use with existing enterprise databases
const sdk = new DeFarmSDK({
database: {
type: 'oracle',
host: 'oracle.company.com',
user: 'defarm_user',
password: process.env.ORACLE_PASSWORD
}
});// Query using enterprise adapter
const assets = await sdk.queryData({
type: 'livestock',
status: 'active',
location: 'Region-North'
});
`$3
`javascript
// Track events across the supply chain
await sdk.trackSupplyChainEvent({
type: 'transfer',
asset_id: 'ASSET-123',
from: 'Farm A',
to: 'Processing Plant B',
transport: 'Truck-789',
temperature: 4.5,
timestamp: Date.now()
});// Get complete history
const history = await sdk.getAssetHistory('ASSET-123');
`$3
`javascript
// Generate compliance reports
const report = await sdk.generateComplianceReport({
standards: ['ISO-22000', 'GLOBALG.A.P'],
period: 'Q4-2024',
regions: ['Brazil', 'Argentina']
});// Validate with schemas
const validation = await sdk.validateWithSchema(
productData,
'organic-certification-v2'
);
`$3
`javascript
// Sign documents with Brazilian digital certificate
const signed = await sdk.signWithICPBrasil({
document: invoiceData,
certificate: '/path/to/cert.pfx'
});
`Business Models
$3
| Plan | Monthly | Tokenizations | Features |
|------|---------|--------------|----------|
| Starter | R$ 2,900 | 1,000/month | Basic features, email support |
| Professional | R$ 9,900 | 10,000/month | All features, priority support |
| Enterprise | R$ 29,900 | 100,000/month | White-label, SLA, dedicated support |
| Government | Custom | Unlimited | Full customization, on-premise |
$3
- Perpetual License: One-time payment + annual maintenance
- Annual Subscription: Full support and updates included
- Custom Development: Tailored solutions for specific needs
Architecture
`
βββββββββββββββββββββββββββββββββββββββββββββββ
β Client Application β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββββββββββββ
β DeFarm SDK Enterprise β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β WASM β β Core β β Services β β
β βProcessor β β Engine β β Client β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β ββββββββββββββββββββββββββββββββββββββββ β
β β Database Adapters β β
β β PostgreSQL | Oracle | SQL Server β β
β ββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β ββββββββββββββββββββββββββββββββββββββββ β
β β Blockchain Integration β β
β β Stellar | Polygon | Ethereum β β
β ββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββββββββββββ
β DeFarm Relay Server β
β (Gas Sponsorship Service) β
βββββββββββββββββββββββββββββββββββββββββββββββ
`API Reference
$3
-
initialize(config) - Initialize the SDK
- processAgricultureData(data, options) - Process agricultural data
- createAssetToken(assetData, options) - Create blockchain token
- trackSupplyChainEvent(event, options) - Track supply chain events
- queryData(query, options) - Query stored data
- getAssetHistory(assetId) - Get asset history$3
-
processWithProcessor(type, data) - Use specific processor (livestock, crops)
- validateWithSchema(data, schema) - Validate with enterprise schemas
- checkDuplicates(data) - Check for duplicate entries
- signWithICPBrasil(data) - Sign with ICP-Brasil certificate
- getAnalytics(query) - Get premium analytics
- setDeploymentMode(mode) - Switch deployment modeDocker Deployment
`bash
Build Docker image
docker build -t defarm-sdk .Run with environment variables
docker run -d \
-e DEFARM_ENV=production \
-e DEFARM_DB_HOST=postgres.local \
-e DEFARM_API_KEY=your-api-key \
-p 3000:3000 \
defarm-sdk
`Environment Variables
`env
Database
DEFARM_DB_TYPE=postgresql
DEFARM_DB_HOST=localhost
DEFARM_DB_PORT=5432
DEFARM_DB_NAME=defarm
DEFARM_DB_USER=defarm_user
DEFARM_DB_PASSWORD=secure_passwordBlockchain
DEFARM_BLOCKCHAIN_ENABLED=true
DEFARM_BLOCKCHAIN_NETWORK=stellar
DEFARM_RELAY_URL=https://relay.defarm.ioEnterprise
DEFARM_API_KEY=your-api-key
DEFARM_DEPLOYMENT_MODE=hybrid
``- Documentation: docs.defarm.io
- Enterprise Sales: enterprise@defarm.io
- Technical Support: support@defarm.io
- GitHub: github.com/defarm/sdk
MIT License for open-source components.
Enterprise features require a commercial license.
---
Built with β€οΈ by the DeFarm Team