Explore real-world implementations and learn through practical examples. From basic blockchain queries to complex DeFi integrations.
Build a complete DeFi portfolio management system that tracks assets across multiple protocols, calculates yields, and automates rebalancing strategies.
// DeFi Portfolio Manager Example
class PortfolioManager {
constructor() {
this.protocols = ['Flamingo', 'NeoFS', 'NeoBurger'];
this.rebalanceThreshold = 0.05; // 5%
}
async getPortfolioValue() {
const balances = await Promise.all(
this.protocols.map(protocol =>
this.getProtocolBalance(protocol)
)
);
return balances.reduce((total, balance) =>
total + balance.usdValue, 0
);
}
async autoRebalance() {
const currentAllocation = await this.getCurrentAllocation();
const targetAllocation = this.getTargetAllocation();
for (const [protocol, current] of Object.entries(currentAllocation)) {
const target = targetAllocation[protocol];
const deviation = Math.abs(current - target);
if (deviation > this.rebalanceThreshold) {
await this.rebalanceProtocol(protocol, target - current);
}
}
}
}
Get basic blockchain information including block height, network status, and node information.
// Get blockchain information
const blockchainInfo = await neo.callTool('get_blockchain_info');
console.log('Current block height:', blockchainInfo.blockcount);
console.log('Network:', blockchainInfo.network);
console.log('Protocol version:', blockchainInfo.protocol);
// Get specific block
const block = await neo.callTool('get_block', {
block_identifier: 'latest'
});
console.log('Latest block hash:', block.hash);
console.log('Transactions:', block.tx.length);
Create wallets, check balances, and manage multiple addresses with comprehensive wallet operations.
// Create a new wallet
const wallet = await neo.callTool('create_wallet', {
password: 'securePassword123!'
});
console.log('New wallet address:', wallet.address);
// Check wallet balance
const balance = await neo.callTool('get_balance', {
address: wallet.address
});
console.log('NEO balance:', balance.NEO);
console.log('GAS balance:', balance.GAS);
// Get all balances for multiple tokens
const allBalances = await neo.callTool('get_all_balances', {
address: wallet.address
});
allBalances.forEach(token => {
console.log(`${token.symbol}: ${token.amount}`);
});
Invoke smart contract methods and interact with deployed contracts on the Neo N3 network.
// Invoke a smart contract method
const result = await neo.callTool('invoke_contract', {
contract_hash: '0xd2a4cff31913016155e38e474a2c06d08be276cf',
method: 'symbol',
parameters: []
});
console.log('Contract result:', result.stack[0].value);
// Invoke with parameters
const transferResult = await neo.callTool('invoke_contract', {
contract_hash: '0xd2a4cff31913016155e38e474a2c06d08be276cf',
method: 'transfer',
parameters: [
{ type: 'Hash160', value: fromAddress },
{ type: 'Hash160', value: toAddress },
{ type: 'Integer', value: '1000000000' },
{ type: 'Any', value: null }
]
});
console.log('Transfer successful:', transferResult.state === 'HALT');
Interact with Flamingo DEX for token swaps, liquidity provision, and yield farming operations.
// Swap tokens on Flamingo DEX
const swapResult = await neo.callTool('invoke_flamingo_swap', {
from_token: 'NEO',
to_token: 'GAS',
amount: '1000000000', // 1 NEO in satoshis
slippage_tolerance: 0.01 // 1%
});
console.log('Swap transaction:', swapResult.txid);
// Add liquidity to a pool
const liquidityResult = await neo.callTool('invoke_flamingo_add_liquidity', {
token_a: 'NEO',
token_b: 'GAS',
amount_a: '1000000000',
amount_b: '50000000000',
min_liquidity: '0'
});
console.log('Liquidity added:', liquidityResult.txid);
// Check pool information
const poolInfo = await neo.callTool('get_flamingo_pool_info', {
pool_id: 'NEO_GAS'
});
console.log('Pool reserves:', poolInfo.reserves);
console.log('Pool APY:', poolInfo.apy);
Send NEP-17 tokens with proper fee estimation and transaction confirmation.
// Transfer NEO tokens
const transferResult = await neo.callTool('transfer_assets', {
from_address: 'NdUL5oDPD159KeFpD5A9zw5xNF1xLX6nLT',
to_address: 'NNLi44dJNXtDNSBkofB48aTVYtb1zZrNEs',
asset: 'NEO',
amount: '1',
fee_estimate: true
});
console.log('Transfer transaction:', transferResult.txid);
console.log('Network fee:', transferResult.networkfee);
// Transfer GAS with custom fee
const gasTransfer = await neo.callTool('transfer_assets', {
from_address: 'NdUL5oDPD159KeFpD5A9zw5xNF1xLX6nLT',
to_address: 'NNLi44dJNXtDNSBkofB48aTVYtb1zZrNEs',
asset: 'GAS',
amount: '10.5',
network_fee: '0.0015'
});
// Monitor transaction status
const txStatus = await neo.callTool('get_transaction_status', {
txid: gasTransfer.txid
});
console.log('Transaction confirmed:', txStatus.confirmed);
Create and manage multi-signature wallets with multiple signers and threshold requirements.
// Create multi-signature wallet
const multiSigWallet = await neo.callTool('create_multisig_wallet', {
public_keys: [
'03aa052fbfb608d3635a4cb4c2a6060e7b16f19501c0e86a0b2b1cc1fa25ac5c55',
'02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2',
'03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c'
],
threshold: 2,
witness_script: true
});
console.log('Multi-sig address:', multiSigWallet.address);
console.log('Script hash:', multiSigWallet.script_hash);
// Create and sign transaction
const unsignedTx = await neo.callTool('create_multisig_transaction', {
from_address: multiSigWallet.address,
to_address: 'NNLi44dJNXtDNSBkofB48aTVYtb1zZrNEs',
asset: 'GAS',
amount: '5.0'
});
// Sign with first key
const partiallySignedTx = await neo.callTool('sign_multisig_transaction', {
transaction: unsignedTx,
private_key: 'private_key_1',
public_keys: multiSigWallet.public_keys
});
// Sign with second key and broadcast
const fullySignedTx = await neo.callTool('sign_multisig_transaction', {
transaction: partiallySignedTx,
private_key: 'private_key_2',
public_keys: multiSigWallet.public_keys,
broadcast: true
});
console.log('Multi-sig transaction sent:', fullySignedTx.txid);
Build decentralized finance applications with automated trading, yield farming, and liquidity management
Create blockchain games with NFT assets, player economies, and decentralized marketplaces
Develop enterprise blockchain solutions for supply chain, identity, and business process automation
Build comprehensive blockchain analytics and monitoring tools for tracking assets and transactions
Develop security-focused applications with multi-signature wallets and advanced key management
Create interoperability solutions connecting Neo N3 with other blockchain networks