aelf 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 41쪽 중 4쪽

dOptions ? : SendOptions ; } const Demo = ( ) => { const { callSendMethod } = useConnectWallet ( ) ; const [ result , setResult ] = useState ( { } ) ; const onApproveHandler = async ( ) => { const res = await callSendMethod ( { chainId : 'tDVW' , contractAddress : 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE' , methodName : 'Approve' , args : { symbol : 'ELF' , spender : 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE' , amount : '100000000' , } , } ) ; setResult ( res ) ; } return ( < div > < Button onClick = { onApproveHandler } > Approve in tDVW </ Button > < div > < h4 > Result </ h4 > < pre className = " result " > { JSON . stringify ( result , null , ' ' ) } </ pre > </ div > </ div > ) } callViewMethod ​ callViewMethod : < T , R > ( props : ICallContractParams < T > ) => Promise < R > Call contract's view method import { Button } from 'aelf-design' ; interface ICallContractParams < T > { contractAddress : string ; methodName : string ; args : T ; chainId ? : TChainId ; sendOptions ? : SendOptions ; // only send method use, ignore in view method } const Demo = ( ) => { const { callViewMethod , getAccountByChainId } = useConnectWallet ( ) ; const [ result , setResult ] = useState ( { } ) ; const onGetBalanceHandler = async ( ) => { const res = await callViewMethod ( { chainId : 'tDVW' , contractAddress : 'ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx' , methodName : 'GetBalance' , args : { symbol : 'ELF' , owner : await getAccountByChainId ( 'tDVW' ) , } , } ) ; setResult ( res ) ; } return ( < div > < Button onClick = { onGetBalanceHandler } > GetBalance in tDVW </ Button > < div > < h4 > Result </ h4 > < pre className = " result " > { JSON . stringify ( result , null , ' ' ) } </ pre > </ div > </ div > ) } walletInfo ​ const walletInfo : TWalletInfo Wallet information after connecting wallet, can import TWalletInfo from @aelf-web-login/wallet-adapter-base type TWalletInfo = | { name ? : string ; address : string ; extraInfo ? : { [ key : string ] : any ; } ; } | undefined ; // walletInfo returned by nightElf { name , address , extraInfo : { publicKey , nightElfInfo : { name , appPermission , defaultAElfBridge : bridge , aelfBridges : bridges , nodes , } , } , } // walletInfo returned by portkeyAA import { DIDWalletInfo } from '@portkey/did-ui-react' ; { name , address , extraInfo : { publicKey , portkeyInfo : { ... DIDWalletInfo accounts : { [ chainId ] : didWalletInfo . caInfo ?. caAddress , } , nickName , } , } , } // walletInfo returned by portkeyDiscover import type { Accounts , IPortkeyProvider } from '@portkey/provider-types' ; { address , extraInfo : { accounts : Accounts , nickName , provider : IPortkeyProvider , } , } const Demo = ( ) => { const { walletInfo } = useConnectWallet ( ) ; console . log ( walletInfo ) return null } walletType ​ const walletType : WalletTypeEnum The currently connected wallet type, can import WalletTypeEnum from @aelf-web-login/wallet-adapter-base enum WalletTypeEnum { unknown = 'Unknown' , elf = 'NightElf' , aa = 'PortkeyAA' , discover = 'PortkeyDiscover' , } const Demo = ( ) => { const { walletType } = useConnectWallet ( ) ; console . log ( walletType ) return null } isLocking ​ const isLocking : boolean indicate whether the current state is locked, only portkeyAA wallet take effect, other wallets always return false import { Button } from 'aelf-design' ; const Demo = ( ) => { const { isLocking } = useConnectWallet ( ) ; return ( < Button > { isLocking ? 'unlock' : 'connect' } </ Button > ) } isConnected ​ const isConnected : boolean indicate whether the current state is connected import { Button } from 'aelf-design' ; const Demo = ( ) => { const { isConnected } = useConnectWallet ( ) ; return ( < div > < Button disabled = { isConnected } > connect </ Button > < Button disabled = { ! isConnected } > disConnect </ Button > </ div > ) } loginError ​ const loginError : TWalletError | null indicate are there any errors during the login/logout/unlock process type TWalletError = { name : string ; code : number ; message : string ; nativeError ? : any ; } const Demo = ( ) => { const { loginError } = useConnectWallet ( ) ; useEffect ( ( ) => { if ( ! loginError ) { return ; } console . log ( loginError . message ) ; } , [ loginError ] ) ; return null } Development ​ Install dependencies in the project root directory pnpm install cd to demo directory and execute dev command cd packages/starter pnpm dev Publish ​ Upgrade the version numbers of each sub package execute release command in the project root directory pnpm release Introduction Install Config Usage API connectWallet disConnectWallet lock getAccountByChainId getWalletSyncIsCompleted getSignature callSendMethod callViewMethod walletInfo walletType isLocking isConnected loginError Development Publish ## /resources/wallet-and-block-explorer On this page Wallet and Block Explorer Description : A comprehensive blockchain explorer for viewing blocks and transactions, purchasing resources, voting, and more. Purpose : To provide users with easy access to blockchain data and functionalities, enhancing their interaction with the network. iOS/Android Wallet Description : A mobile wallet app for managing assets and trading across blockchains on iOS and Android. Purpose : To offer users a convenient way to manage their digital assets and enable developers to integrate their applications with the wallet SDK. Web Wallet Description : A web-based wallet for handling blockchain transactions directly from the browser. Purpose : To facilitate easy and basic transaction management for users via a web interface. Explorer API Description : An API for interacting with blockchain data, including blocks, transactions, and TPS records. Purpose : To allow developers to retrieve detailed blockchain information programmatically, supporting various use cases such as monitoring and analysis. Wallet and Block Explorer Explorer ​ Github Overview Our blockchain explorer lets you do a lot of things easily. You can view blocks and transactions, buy resources, vote, campaign for node roles, and check out contracts. Features ​ View Blocks and Transactions : Track the latest blocks and transactions on the network. Purchase Resources : Buy necessary resources for your operations. Voting and Node Campaigning : Participate in network governance by voting and running for node roles. View Contracts : Access and review smart contracts. iOS/Android Wallet ​ Overview The mobile wallet app for iOS and Android helps you manage your assets and trade across different blockchains. It also offers a platform for developers to integrate their applications using the wallet SDK. Features Basic Asset Management : Easily manage your digital assets. Cross-Chain Trading : Trade assets across different blockchains seamlessly. Developer Platform : Access the wallet SDK to integrate your applications. Web Wallet ​ Github Overview ​ The web wallet offers basic functionalities for handling transactions right from your browser. Features Transaction Management: Handle your transactions with ease. Explorer API ​ To get more information by code Our Explorer API allows you to interact with blockchain data. You can get information about blocks, transactions, and TPS (transactions per second). Here’s how you can use it: Blocks ​ Get Block List ​ URL : api/all/blocks?limit={limit}&page={page} Method : GET Description : Retrieve a list of blocks. Success Response: { "total" : 5850 , "blocks" : [ { "block_hash" : "7e1c2fb6d3cc5e8c2cef7d75de9c1adf0e25e9d17d4f22e543fa20f5f23b20e9" , "pre_block_hash" : "6890fa74156b1a88a3ccef1fef72f4f78ff2755ffcd4fb5434ed7b3c153061f5" , "chain_id" : "AELF" , "block_height" : 5719 , "tx_count" : 1 , "merkle_root_tx" : "47eabbc7a499764d0b25c7216ba75fe39717f9866a0716c8a0d1798e64852d84" , "merkle_root_state" : "d14e78dc3c7811b7c17c8b04ebad9e547c35b3faa8bfcc9189b8c12e9f6a4aae" , "time" : "2019-04-27T02:00:34.691118Z" } , { "block_hash" : "6890fa74156b1a88a3ccef1fef72f4f78ff2755ffcd4fb5434ed7b3c153061f5" , "pre_block_hash" : "f1098bd6df58acf74d8877529702dffc444cb401fc8236519606aa9165d945ae" , "chain_id" : "AELF" , "block_height" : 5718 , "tx_count" : 1 , "merkle_root_tx" : "b29b416148b4fb79060eb80b49bb6ac25a82da2d7a1c5d341e0bf279a7c57362" , "merkle_root_state" : "4dbef401f6d9ed303cf1b5e609a64b1c06a7fb77620b9d13b0e4649719e2fe55" , "time" : "2019-04-27T02:00:34.691118Z" } , { "block_hash" : "f1098bd6df58acf74d8877529702dffc444cb401fc8236519606aa9165d945ae" , "pre_block_hash" : "1fbdf3a4fb3c41e9ddf25958715815d9d643dfb39e1aaa94631d197e9b1a94bb" , "chain_id" : "AELF" , "block_height" : 5717 , "tx_count" : 1 , "merkle_root_tx" : "776abba03d66127927edc6437d406f708b64c1653a1cc22af9c490aa4f0c22dc" , "merkle_root_state" : "ccc32ab23d619b2b8e0e9b82a53bb66b3a6d168993188b5d3f7f0ac2cb17206f" , "time" : "2019-04-27T02:00:26.690003Z" } ] } Get Block List By Block Hash ​ URL : api/block/transactions?limit={limit}&page={page}&order={order}&block_hash={block_hash} Method : GET Description : Retrieve a list of blocks using a specific block hash. Success Response: { "transactions" : [ { "tx_id" : "209ceb8ee88eeb2c55db7783c48ec0b1adf6badba89fc7ddb86e968601027cbb" , "chain_id" : "AELF" , "block_height" : 590 , "address_from" : "csoxW4vTJNT9gdvyWS6W7UqEdkSo9pWyJqBoGSnUHXVnj4ykJ" , "address_to" : "2gaQh4uxg6tzyH1ADLoDxvHA14FMpzEiMqsQ6sDG5iHT8cmjp8" , "method" : "DeploySmartContract" , "block_hash" : "79584a99b7f5da5959a26ff02cbe174d632eb5ef3c6c8d5192de48b6f5584c8d" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T06:47:00.265604Z" } , { "tx_id" : "d9398736920a5c87ea7cae46c265efa84ac7be4cf8edd37bea54078abef1b44c" , "params_to" : "" , "chain_id" : "AELF" , "block_height" : 590 , "address_from" : "2EyPedNTscFK5EwR8FqTrCeW2LZzuPQ7vr18Y5QWuEUApdCkM6" , "address_to" : "xw6U3FRE5H8rU3z8vAgF9ivnWSkxULK5cibdZzMC9UWf7rPJf" , "params" : "" , "method" : "NextRound" , "block_hash" : "79584a99b7f5da5959a26ff02cbe174d632eb5ef3c6c8d5192de48b6f5584c8d" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T06:47:00.265604Z" } ] } Transactions ​ Get Transactions List ​ URL : api/all/transactions?limit={limit}&page={page} Method : GET Description : Retrieve a list of transactions. Success Response: { "total" : 1179 , "transactions" : [ { "tx_id" : "c65d1206e65aaf2e7e08cc818c372ff2c2947cb6cbec746efe6a5e20b7adefa9" , "chain_id" : "AELF" , "block_height" : 1064 , "address_from" : "grSAEQ5vJ7UfCN2s1v4fJJnk98bu4SHa2hpQkQ9HT88rmaZLz" , "address_to" : "xw6U3FRE5H8rU3z8vAgF9ivnWSkxULK5cibdZzMC9UWf7rPJf" , "method" : "NextRound" , "block_hash" : "8c922b20164ad3774b56d19673154f383ed89656cbd56433d1681c8c3a4dcab9" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T07:18:36.636701Z" } , { "tx_id" : "4780a7b2737b6f044894719b9bb4cb09862c0b4a7cae267131a0b5c3e7c12850" , "params_to" : "" , "chain_id" : "AELF" , "block_height" : 1063 , "address_from" : "QUYYqzTQmugruHYmuJVftwmVjnUM82pXnMTnT5jh55qwZKrMw" , "address_to" : "xw6U3FRE5H8rU3z8vAgF9ivnWSkxULK5cibdZzMC9UWf7rPJf" , "params" : "" , "method" : "UpdateValue" , "block_hash" : "381114b86b09886f59956851a1d47d8442b29f44f3785dade3c667ca320e23bb" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T07:18:36.636701Z" } , { "tx_id" : "0230385e3f060059d2a62addac09ad6d01f96d32ec076cfbf44c6a3b70c6e092" , "params_to" : "" , "chain_id" : "AELF" , "block_height" : 1062 , "address_from" : "zizPhdDpQCZxMChMxn1oZ4ttJGJUo61Aocg5BpTYvzLQGmBjT" , "address_to" : "xw6U3FRE5H8rU3z8vAgF9ivnWSkxULK5cibdZzMC9UWf7rPJf" , "params" : "" , "method" : "NextRound" , "block_hash" : "06a3ceb783480f4cf5b8402f6749617093d9ea5f9a053f65e86554aeed6d98f4" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T07:18:28.635113Z" } ] } Get Transactions List By Address ​ URL : api/address/transactions?contract_address={contract_address}&limit={limit}&page={page}&address={address} Method : GET Description : Retrieve a list of transactions associated with a specific address. Success Response: { "total" : 1179 , "transactions" : [ { "tx_id" : "c65d1206e65aaf2e7e08cc818c372ff2c2947cb6cbec746efe6a5e20b7adefa9" , "chain_id" : "AELF" , "block_height" : 1064 , "address_from" : "grSAEQ5vJ7UfCN2s1v4fJJnk98bu4SHa2hpQkQ9HT88rmaZLz" , "address_to" : "xw6U3FRE5H8rU3z8vAgF9ivnWSkxULK5cibdZzMC9UWf7rPJf" , "method" : "NextRound" , "block_hash" : "8c922b20164ad3774b56d19673154f383ed89656cbd56433d1681c8c3a4dcab9" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T07:18:36.636701Z" } , { "tx_id" : "4780a7b2737b6f044894719b9bb4cb09862c0b4a7cae267131a0b5c3e7c12850" , "params_to" : "" , "chain_id" : "AELF" , "block_height" : 1063 , "address_from" : "QUYYqzTQmugruHYmuJVftwmVjnUM82pXnMTnT5jh55qwZKrMw" , "address_to" : "xw6U3FRE5H8rU3z8vAgF9ivnWSkxULK5cibdZzMC9UWf7rPJf" , "params" : "" , "method" : "UpdateValue" , "block_hash" : "381114b86b09886f59956851a1d47d8442b29f44f3785dade3c667ca320e23bb" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T07:18:36.636701Z" } , { "tx_id" : "0230385e3f060059d2a62addac09ad6d01f96d32ec076cfbf44c6a3b70c6e092" , "params_to" : "" , "chain_id" : "AELF" , "block_height" : 1062 , "address_from" : "zizPhdDpQCZxMChMxn1oZ4ttJGJUo61Aocg5BpTYvzLQGmBjT" , "address_to" : "xw6U3FRE5H8rU3z8vAgF9ivnWSkxULK5cibdZzMC9UWf7rPJf" , "params" : "" , "method" : "NextRound" , "block_hash" : "06a3ceb783480f4cf5b8402f6749617093d9ea5f9a053f65e86554aeed6d98f4" , "quantity" : 0 , "tx_status" : "Mined" , "time" : "2019-04-26T07:18:28.635113Z" } ] } TPS (Transactions Per Second) ​ Get TPS Record ​ URL : api/tps/list?start_time={unix_timestamp}&end_time={unix_timestamp}&order={order} Method : GET Description : Obtain TPS records for performance monitoring. Success Response: { "total" : 178 , "tps" : [ { "id" : 12498 , "start" : "2019-11-22T01:12:14Z" , "end" : "2019-11-22T01:13:14Z" , "txs" : 1878 , "blocks" : 120 , "tps" : 31 , "tpm" : 1878 , "type" : 1 } , { "id" : 12499 , "start" : "2019-11-22T01:13:14Z" , "end" : "2019-11-22T01:14:14Z" , "txs" : 1889 , "blocks" : 117 , "tps" : 31 , "tpm" : 1889 , "type" : 1 } , { "id" : 12500 , "start" : "2019-11-22T01:14:14Z" , "end" : "2019-11-22T01:15:14Z" , "txs" : 1819 , "blocks" : 114 , "tps" : 30 , "tpm" : 1819 , "type" : 1 } , { "id" : 12501 , "start" : "2019-11-22T01:15:14Z" , "end" : "2019-11-22T01:16:14Z" , "txs" : 1779 , "blocks" : 105 , "tps" : 30 , "tpm" : 1779 , "type" : 1 } ] } Explorer Features iOS/Android Wallet Web Wallet Overview Explorer API Blocks Transactions TPS (Transactions Per Second) ## /resources/browser-extension On this page Description : aelf Web Extension is a tool for DApp developers to interact with the aelf blockchain. Purpose : This guide provides instructions for both users and developers on the installation, usage, and implementation of the aelf Web Extension. aelf-web-extension ​ Introduction ​ aelf Web Extension provides an interface for DApp developers to interact with the aelf blockchain. This guide outlines the usage and implementation details for both users and developers. For Users ​ Release Version ​ Please wait for the official release. Development Version ​ dev version For those using QQ Browser and similar, you can add the extension manually. Notice ​ Note : Using File:/// protocol may can not use the extenstion //. You must opt in to file access for each extension that requests it. For more details, visit the Chrome Developer Documentation . For DApp Developers ​ Interaction Flow ​ Ensure the user has installed the extension. Connect to the blockchain. Initialize the contract. Call contract methods. How to Use ​ To access the complete data structure, click here . For an extension demo, refer to the provided examples. aelf-web-extension Introduction For Users Release Version Development Version Notice For DApp Developers Interaction Flow How to Use Data Format Demo of Checking the Extension GET_CHAIN_STATUS Token Transfer Expected Result : CALL_AELF_CHAIN Expected Result : LOGIN INIT_AELF_CONTRACT Expected Result : CALL_AELF_CONTRACT / CALL_AELF_CONTRACT_READONLY CHECK_PERMISSION Expected Result : SET_CONTRACT_PERMISSION Expected Result REMOVE_METHODS_WHITELIST Expected Result For Extension Developers Project Information Data Format ​ { "histories" : [ ] , "keychain" : { "keypairs" : [ { "name" : "your keypairs name" , "address" : "your keypairs address" , "mnemonic" : "your keypairs mnemonic" , "privateKey" : "your keypairs privateKey" , "publicKey" : { "x" : "your keypairs publicKey" , "y" : "your keypairs publicKey" } } ] , "permissions" : [ { "chainId" : "AELF" , "contractAddress" : "contract address" , "contractName" : "contract name" , "description" : "contract description" , "github" : "contract github" , "whitelist" : { "Approve" : { "parameter1" : "a" , "parameter2" : "b" , "parameter3" : "c" } } } ] } } Demo of Checking the Extension ​ let nightElfInstance = null ; class NightElfCheck { constructor ( ) { const readyMessage = 'NightElf is ready' ; let resolveTemp = null ; this . check = new Promise ( ( resolve , reject ) => { if ( window . NightElf ) { resolve ( readyMessage ) ; } setTimeout ( ( ) => { reject ( { error : 200001 , message : 'timeout / cannot find NightElf / please install the extension' } ) ; } , 1000 ) ; resolveTemp = resolve ; } ) ; document . addEventListener ( 'NightElf' , result => { console . log ( 'Checking the status of extension named NightElf: ' , result ) ; resolveTemp ( readyMessage ) ; } ) ; } static getInstance ( ) { if ( ! nightElfInstance ) { nightElfInstance = new NightElfCheck ( ) ; return nightElfInstance ; } return nightElfInstance ; } } const nightElfCheck = NightElfCheck . getInstance ( ) ; nightElfCheck . check . then ( message => { // connectChain -> Login -> initContract -> call contract methods } ) ; GET_CHAIN_STATUS ​ You can see the demo ./devDemos/test.html . [demo.js just a draft] Token Transfer ​ If you want to check Token Transfer Demo. You can Click Here The methods calls act the same as the methods call of the aelf-sdk.js Note : ... stands for omitted data. const aelf = new window . NightElf . AElf ( { httpProvider : [ 'http://192.168.197.56:8101/chain' ] , appName : 'Test' } ) ; aelf . chain . getChainStatus ( ( error , result ) => { console . log ( 'Chain Status:' , error , result ) ; } ) ; Expected Result : ​ result = { ChainId : "AELF" GenesisContractAddress : "61W3AF3Voud7cLY2mejzRuZ4WEN8mrDMioA9kZv3H8taKxF" } CALL_AELF_CHAIN ​ Example of retrieving a transaction result: const txid = 'c45edfcca86f4f528cd8e30634fa4ac53801aae05365cfefc3bfe9b652fe5768' ; aelf . chain . getTxResult ( txid , ( err , result ) => { console . log ( 'Transaction Result:' , err , result ) ; } ) ; Expected Result : ​ result = { Status : "NotExisted" TransactionId : "ff5bcd126f9b7f22bbfd0816324390776f10ccb3fe0690efc84c5fcf6bdd3fc6" } LOGIN ​ Example login call: aelf . login ( { appName : 'hzzTest' , chainId : 'AELF' , payload : { method : 'LOGIN' , contracts : [ {
프로젝트로 돌아가기