{"id":26562931,"url":"https://github.com/aelfproject/aelf-web-extension","last_synced_at":"2025-07-18T22:34:20.434Z","repository":{"id":43279774,"uuid":"164632877","full_name":"AElfProject/aelf-web-extension","owner":"AElfProject","description":"aelf-web-extension","archived":false,"fork":false,"pushed_at":"2024-11-04T10:41:02.000Z","size":60389,"stargazers_count":5,"open_issues_count":12,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-17T13:52:05.046Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AElfProject.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/SupportedBlockchains/Chain/AELF.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-01-08T11:19:03.000Z","updated_at":"2022-03-10T08:45:46.000Z","dependencies_parsed_at":"2025-06-17T13:54:00.173Z","dependency_job_id":null,"html_url":"https://github.com/AElfProject/aelf-web-extension","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/AElfProject/aelf-web-extension","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-web-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-web-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-web-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-web-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AElfProject","download_url":"https://codeload.github.com/AElfProject/aelf-web-extension/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AElfProject%2Faelf-web-extension/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265846886,"owners_count":23838160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-22T15:29:20.288Z","updated_at":"2025-07-18T22:34:20.416Z","avatar_url":"https://github.com/AElfProject.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aelf-web-extension\n\n## 1 For User\n\n[release version, please waiting](#)\n\n[dev version](https://chrome.google.com/webstore/detail/aelf-explorer-extension-d/mlmlhipeonlflbcclinpbmcjdnpnmkpf)\n\nIf you are using qq browser,etc, you can add the extention too.\n\n### 1.1 Notice\n\n```note\nUsing File:/// protocol may can not use the extenstion\n// https://developer.chrome.com/extensions/match_patterns\nNote: Access to file URLs isn't automatic. The user must visit the extensions management page and opt in to file access for each extension that requests it.\n```\n\n## 2 For Dapp Developers\n\n####Please get code in ./devDemos, open test.html \u0026 test.js(need use you own wallet address) and you will get everything you want.\n\n### 2.1 Interaction Flow\n\n- 1.Make sure the user get the Extension\n- 2.Connect the blockchain\n- 3.Initialize contract / Call the methods of the blockchain\n- 4.Call the methods of contract \n\n### 2.2 Demo of Checking the Extension\n\nYou can skip this when you first read this.\n\n```js\nlet nightElfInstance = null;\nclass NightElfCheck {\n    constructor() {\n        const readyMessage = 'NightElf is ready';\n        let resovleTemp = null;\n        this.check = new Promise((resolve, reject) =\u003e {\n            if (window.NightElf) {\n                resolve(readyMessage);\n            }\n            setTimeout(() =\u003e {\n                reject({\n                    error: 200001,\n                    message: 'timeout / can not find NightElf / please install the extension'\n                });\n            }, 1000);\n            resovleTemp = resolve;\n        });\n        document.addEventListener('NightElf', result =\u003e {\n            console.log('test.js check the status of extension named nightElf: ', result);\n            resovleTemp(readyMessage);\n        });\n    }\n    static getInstance() {\n        if (!nightElfInstance) {\n            nightElfInstance = new NightElfCheck();\n            return nightElfInstance;\n        }\n        return nightElfInstance;\n    }\n}\nconst nightElfCheck = NightElfCheck.getInstance();\nnightElfCheck.check.then(message =\u003e {\n    // connectChain -\u003e Login -\u003e initContract -\u003e call contract methods\n});\n```\n\n### 2.3 How Connect the blockchain\n\n`v1.1.3 add key: pure`\n\n```javascript\nconst aelf = new window.NightElf.AElf({\n    httpProvider: [\n        'http://127.0.0.1:8101',\n    ],\n    appName: 'your own app name',\n    // If you don't set pure=true, you will get old data structure which is not match aelf-sdk.js return.\n    // v1.1.3  \n    pure: true\n});\n```\n### 2.4 How to call the API\n\nCallback or promise are both ok.\n\n```javascript\n// callback\naelf.chain.getChainStatus((error, result) =\u003e {\n    console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e getChainStatus \u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e');\n    console.log(error, result);\n});\n\n// promise\naelf.chain.getChainStatus().then(result =\u003e {\n    console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e getChainStatus \u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e');\n    console.log('promise then', result);\n}).catch(error =\u003e {\n    console.log('promise catch', error);\n});\n```\n\n\u003cspan id=\"check-extension-demo\"\u003e\u003c/span\u003e\n\n## 3 API Reference\n\nHere you can find examples and in-depth information about NightELF's API.\n\nYou can see the demo code. [click here](https://github.com/AElfProject/aelf-web-extension/blob/master/devDemos/test.html)\n\nIf you want to check token transfer demo. [click here](https://github.com/AElfProject/aelf-web-extension/blob/master/demo/token/demo.html)\n\nThe methods act the same as the methods of the aelf-sdk.js\n\n- [0. GET_VERSION](#get-version)\n- [1. LOGIN](#login)\n- [2. GET_CHAIN_STATUS](#get-chain-status)\n- [3. CALL_AELF_CHAIN](#call-aelf-chain)\n- [4. INIT_AELF_CONTRACT](#init-aelf-contract)\n- [5. CALL_AELF_CONTRACT / CALL_AELF_CONTRACT_READONLY](#call-aelf-contract)\n- [6. CHECK_PERMISSION](#check-permission) [avoid \u003e=v1.1.3]\n- [7. SET_CONTRACT_PERMISSION](#set-contract-permission) [avoid \u003e=v1.1.3]\n- [8. REMOVE_CONTRACT_PERMISSION](#remove-contract-permission) [avoid \u003e=v1.1.3]\n- [9. REMOVE_METHODS_WHITELIST](#remove-methods-whitelist)\n- [10. GET_SIGNATURE](#get-signature)\n\n\u003cspan id=\"get-version\"\u003e\u003c/span\u003e\n\n### 3.0 GET_VERSION\n\n```javascript\naelf.getVersion() // v1.1.3\n```\n\n\u003cspan id=\"login\"\u003e\u003c/span\u003e\n\n### 3.1 LOGIN\n\nLOGIN allows your application to request permission to interact with a user's NightELF\nand be provided with an account of the user's choosing. \n\n`v1.1.3 you can ignore contracts`\n\n```javascript\naelf.login({\n    chainId: 'AELF',\n    payload: {\n        method: 'LOGIN',\n        // no more need contracts\n        // v1.1.3\n        /* contracts: [{\n            chainId: 'AELF',\n            contractAddress: '4rkKQpsRFt1nU6weAHuJ6CfQDqo6dxruU3K3wNUFr6ZwZYc',\n            contractName: 'token',\n            description: 'token contract',\n            github: ''\n        }, {\n            chainId: 'AELF TEST',\n            contractAddress: '2Xg2HKh8vusnFMQsHCXW1q3vys5JxG5ZnjiGwNDLrrpb9Mb',\n            contractName: 'TEST contractName',\n            description: 'contract description',\n            github: ''\n        }] */\n    }\n}, (error, result) =\u003e {\n    console.log('login\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e', result);\n});\n\n// result = {\n//     \"error\": 0,\n//     \"errorMessage\": \"\",\n//     \"message\": \"\",\n//     \"detail\": {\n//         \"name\": \"your name\",\n//         \"address\": \"2RCLmZQ2291xDwSbDEJR6nLhFJcMkyfrVTq1i1YxWC4SdY49a6\",\n//         \"publicKey\": {\n//             \"x\": \"4958d5c48f003c771769f4a31413cd18053516615cbde502441af8452fb53441\",\n//             \"y\": \"a80cc48a7f3b0f2552fd030cacbe9012ba055a3d553b70003f2e637d55fa0f23\"\n//         }\n//     },\n//     \"sid\": \"350815427961739930163684\",\n//     \"from\": \"contentNightElf\"\n// }\n\n// the data in the extension\n// keychain = {\n//     keypairs: [{\n//         name: 'your keypairs name',\n//         address: 'your keypairs address',\n//         mnemonic: 'your keypairs mnemonic',\n//         privateKey: 'your keypairs privateKey'，\n//         publicKey: {\n//             x: 'f79c25eb......',\n//             y: '7fa959ed......'\n//         }\n//     }],\n//     permissions: [{\n//         appName: 'hzzTest',\n//         address: 'your keyparis address',\n//         contracts: [{\n//             chainId: 'AELF',\n//             contractAddress: '4rkKQpsRFt1nU6weAHuJ6CfQDqo6dxruU3K3wNUFr6ZwZYc',\n//             contractName: 'token',\n//             description: 'token contract',\n//             github: ''\n//         }],\n//         domain: 'Dapp domain'\n//     }]\n// }\n```\n\n\u003cspan id=\"get-chain-status\"\u003e\u003c/span\u003e\n\n### 3.2 GET_CHAIN_STATUS\n\n```javascript\n\naelf.chain.getChainStatus((error, result) =\u003e {\n    console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e connectChain \u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e');\n    console.log(error, result);\n});\n\n```\n\n\u003cspan id=\"call-aelf-chain\"\u003e\u003c/span\u003e\n\n### 3.3 CALL_AELF_CHAIN\n\n```javascript\n// this txid is an example.\nconst txid = 'c45edfcca86f4f528cd8e30634fa4ac53801aae05365cfefc3bfe9b652fe5768';\naelf.chain.getTxResult(txid, (err, result) =\u003e {\n    console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e getTxResult \u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e');\n    console.log(err, result);\n});\n\n// result = {\n//     Status: \"NotExisted\"\n//     TransactionId: \"c45edfcca86f4f528cd8e30634fa4ac53801aae05365cfefc3bfe9b652fe5768\"\n//     ....\n// }\n```\n\n\u003cspan id=\"init-aelf-contract\"\u003e\u003c/span\u003e\n\n### 3.4 INIT_AELF_CONTRACT\n\n```javascript\n// In aelf-sdk.js wallet is the realy wallet.\n// But in extension sdk, we just need the address of the wallet.\nconst wallet = {\n    address: '2JqnxvDiMNzbSgme2oxpqUFpUYfMjTpNBGCLP2CsWjpbHdu'\n};\n// It is different from the wallet created by Aelf.wallet.getWalletByPrivateKey();\n// There is only one value named address;\naelf.chain.contractAt(\n    '4rkKQpsRFt1nU6weAHuJ6CfQDqo6dxruU3K3wNUFr6ZwZYc',\n    wallet,\n    (error, result) =\u003e {\n        console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e contractAt \u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e');\n        console.log(error, result);\n        tokenContract = result;\n    }\n);\n\n// result = {\n//     Approve: ƒ (),\n//     Burn: ƒ (),\n//     ChargeTransactionFees: ƒ (),\n//     ClaimTransactionFees: ƒ (),\n//     ....\n// }\n```\n\n\u003cspan id=\"call-aelf-contract\"\u003e\u003c/span\u003e\n\n### 3.5 CALL_AELF_CONTRACT / CALL_AELF_CONTRACT_READONLY\n\n```javascript\n// tokenContract from the pre step.\ntokenContract.GetBalance.call(\n    {\n        symbol: 'AELF',\n        owner: '65dDNxzcd35jESiidFXN5JV8Z7pCwaFnepuYQToNefSgqk9'\n    },\n    (err, result) =\u003e {\n        console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e', result);\n    }\n);\n\ntokenContract.Approve(\n    {\n        symbol: 'AELF',\n        spender: '4rkKQpsRFt1nU6weAHuJ6CfQDqo6dxruU3K3wNUFr6ZwZYc',\n        amount: '100'\n    },\n    (err, result) =\u003e {\n        console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e', result);\n    }\n);\n\n// If you use tokenContract.GetBalance.call  this method is only applicable to queries that do not require extended authorization validation.(CALL_AELF_CONTRACT_READONLY)\n// If you use tokenContract.Approve this requires extended authorization validation (CALL_AELF_CONTRACT)\n\n// tokenContract.GetBalance.call(payload, (error, result) =\u003e {})\n// result = {\n//     symbol: \"AELF\",\n//     owner: \"65dDNxzcd35jESiidFXN5JV8Z7pCwaFnepuYQToNefSgqk9\",\n//     balance: 0\n// }\n```\n\n\u003cspan id=\"check-permission\"\u003e\u003c/span\u003e\n\n### 3.6 CHECK_PERMISSION\n\n`v1.1.3 Please avoid the in your new code`\n\nCHECK_PERMISSION returns the contracts your can use with the address.\n\n```javascript\naelf.checkPermission({\n    type: 'address', // if you did not set type, it aways get by domain.\n    address: '4WBgSL2fSem9ABD4LLZBpwP8eEymVSS1AyTBCqXjt5cfxXK'\n}, (error, result) =\u003e {\n    console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e', error, result);\n});\n\n// result = {\n//     ...,\n//     permissions:[\n//         {\n//             address: '...',\n//             appName: 'hzzTest',\n//             contracts: [{\n//                 chainId: 'AELF',\n//                 contractAddress: '4rkKQpsRFt1nU6weAHuJ6CfQDqo6dxruU3K3wNUFr6ZwZYc',\n//                 contractName: 'token',\n//                 description: 'token contract',\n//                 github: ''\n//             },\n//             {\n//                 chainId: 'AELF TEST',\n//                 contractAddress: 'TEST contractAddress',\n//                 contractName: 'TEST contractName',\n//                 description: 'contract description',\n//                 github: ''\n//             }],\n//             domian: 'Dapp domain'\n//         }\n//     ]\n// }\n```\n\n\u003cspan id=\"set-contract-permission\"\u003e\u003c/span\u003e\n\n### 3.7 SET_CONTRACT_PERMISSION\n\n`v1.1.3 Please avoid the in your new code`\n\nSET_CONTRACT_PERMISSION applies to the users to allow the Dapp use the contract.\n\n```javascript\naelf.setContractPermission({\n    chainId: 'AELF',\n    payload: {\n        address: '2JqnxvDiMNzbSgme2oxpqUFpUYfMjTpNBGCLP2CsWjpbHdu',\n        contracts: [{\n            chainId: 'AELF',\n            contractAddress: 'TEST contractAddress',\n            contractName: 'AAAA',\n            description: 'contract description',\n            github: ''\n        }]\n    }\n}, (error, result) =\u003e {\n    console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e', error, result);\n});\n```\n\n\u003cspan id=\"remove-contract-permission\"\u003e\u003c/span\u003e\n\n### 3.8 REMOVE_CONTRACT_PERMISSION\n\n`v1.1.3 Please avoid the in your new code`\n\n```javascript\naelf.removeContractPermission({\n    chainId: 'AELF',\n    payload: {\n        contractAddress: '2Xg2HKh8vusnFMQsHCXW1q3vys5JxG5ZnjiGwNDLrrpb9Mb'\n    }\n}, (error, result) =\u003e {\n    console.log('\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e', error, result);\n});\n```\n\n\u003cspan id=\"remove-methods-whitelist\"\u003e\u003c/span\u003e\n\n### 3.9 REMOVE_METHODS_WHITELIST\n\n```javascript\naelf.removeMethodsWhitelist({\n    chainId: 'AELF',\n    payload: {\n        contractAddress: '2Xg2HKh8vusnFMQsHCXW1q3vys5JxG5ZnjiGwNDLrrpb9Mb',\n        whitelist: ['Approve']\n    }\n}, (error, result) =\u003e {\n    console.log('removeWhitelist\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e', result);\n});\n```\n\n\u003cspan id=\"get-signature\"\u003e\u003c/span\u003e\n\n### 3.10 GET_SIGNATURE\n\n`v1.1.3 User will get a prompt to confirm`\n\n```javascript\naelf.getSignature({\n    address: 'address',\n    hexToBeSign: 'hexToBeSign'\n}).then(result =\u003e {\n  // ...\n}).cathc(error =\u003e {\n  // ...\n});\n```\n\n## 4.For Extension Developers\n\n### 4.1. Download the code\n\n```bash\ngit clone https://github.com/AElfProject/aelf-web-extension.git\n```\n\n### 4.2 Install dependent\n\n```bash\n    npm install\n```\n\n### 4.3 Run webpack\n\n```bash\n    npm run none\n    npm run none:watch\n    npm run dev\n    npm run dev:watch\n    npm run pro\n    npm run pro:watch\n```\n\n### 4.4 Add to the browser\n\n```bash\n    open development mode, add the webpack output app/public.\n```\n   \n### 4.5 How to publish to chrome\n\nzip app/public to public.zip, and follow the notes.\n\n### 4.6 Can not use crx\n\nYou can not install the extension from an offline crx if Chrome \u003e= 73.\n\nPlease import the `.zip file` with developer mode.\n\n\u003cspan id=\"dataformat\"\u003e\u003c/span\u003e\n\n## 5 Formatted Data Example\n\n```javascript\n    NightElf = {\n        histories: [],\n        keychain: {\n            keypairs: [\n                {\n                    name: 'your keypairs name',\n                    address: 'your keypairs address',\n                    mnemonic: 'your keypairs mnemonic',\n                    privateKey: 'your keupairs privateKey',\n                    publicKey: {\n                        x: 'you keupairs publicKey',\n                        y: 'you keupairs publicKey'\n                    }\n                }\n            ],\n            // \u003e= v1.1.3, only whitelist is needed.\n            permissions: [\n                {\n                    chainId: 'AELF',\n                    contractAddress: 'contract address',\n                    contractName: 'contract name',\n                    description: 'contract description',\n                    github: 'contract github',\n                    whitelist: {\n                        Approve: {\n                            parameter1: 'a',\n                            parameter2: 'b',\n                            parameter3: 'c'\n                        }\n                    }\n                }\n            ]\n        }\n    }\n```\n\n## 6 Project Information\n\nWe use [ECDH](https://github.com/indutny/elliptic) to use public key to  encryt data and private key to decrypt data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelfproject%2Faelf-web-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faelfproject%2Faelf-web-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelfproject%2Faelf-web-extension/lists"}