@prathammahajan/blockchain-integration
Version:
🚀 Comprehensive blockchain integration suite with multi-chain cryptocurrency support, NFT marketplace, smart contracts, DeFi protocols, and enterprise-grade wallet management
74 lines (60 loc) • 2.07 kB
JavaScript
const BlockchainEngine = require('../src/index');
async function smartContractsExample() {
try {
// Initialize blockchain engine with smart contract support
const blockchain = new BlockchainEngine({
networks: {
ethereum: {
enabled: true,
rpc: 'https://mainnet.infura.io',
chainId: 1
}
},
wallet: {
enabled: true,
encryption: true
},
smartContracts: {
enabled: true,
deployment: true,
interaction: true
}
});
// Wait for initialization
await new Promise(resolve => {
blockchain.on('initialized', resolve);
});
console.log('✅ Blockchain Engine initialized with smart contract support');
// Create a wallet
const wallet = await blockchain.createWallet('hd');
console.log('✅ Wallet created:', wallet.address);
// Deploy a smart contract
const contractCode = `
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 public storedData;
function set(uint256 x) public {
storedData = x;
}
function get() public view returns (uint256) {
return storedData;
}
}
`;
const deployResult = await blockchain.deployContract(contractCode, []);
console.log('✅ Smart contract deployed:', deployResult);
// Call contract method
const callResult = await blockchain.callContract(deployResult.contractAddress, 'set', [42]);
console.log('✅ Contract method called:', callResult);
// Get contract state
const getResult = await blockchain.callContract(deployResult.contractAddress, 'get', []);
console.log('✅ Contract state retrieved:', getResult);
// Shutdown
await blockchain.shutdown();
console.log('✅ Blockchain Engine shutdown');
} catch (error) {
console.error('❌ Error:', error.message);
}
}
// Run the example
smartContractsExample();