-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from RutvikGhaskataEalf/main
feat: added aelf-smartcontract-viewer package
- Loading branch information
Showing
28 changed files
with
1,634 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package-lock.json | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# aelf-smartcontract-viewer | ||
|
||
The **aelf-smartcontract-viewer** is a React component that provides an easy interface to view and interact with smart contracts on the Aelf blockchain. You can use this component to input contract details and view available read and write methods. This tool is useful for developers building applications around Aelf smart contracts, allowing easy testing and interaction with deployed contracts. | ||
|
||
## Installation | ||
|
||
You can install the package using npm: | ||
|
||
```base | ||
npm install aelf-smartcontract-viewer | ||
``` | ||
|
||
## Usage | ||
|
||
### Basic Example | ||
|
||
```typescript | ||
import React from "react"; | ||
import { ContractView } from "aelf-smartcontract-viewer"; | ||
|
||
const App = () => { | ||
return ( | ||
<div> | ||
<ContractView | ||
address="your_smart_contract_address" | ||
rpcUrl="rpc_url" // i.e = https://explorer-test-side02.aelf.io/chain | ||
contractName="Smart Contract Name" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; | ||
``` | ||
|
||
## Props | ||
|
||
| Prop | Type | Default | Description | | ||
| ------------- | ------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | | ||
| `wallet` | `IWalletInfo` | `undefined` | Optional wallet info. If not provided, a new wallet is generated. | | ||
| `headerTitle` | `string` | `"Aelf Contract View"` | Title for the contract view header. | | ||
| `headerShown` | `boolean` | `true` | Whether the header should be shown or not. | | ||
| `address` | `string` | `undefined` | Address of the contract. If not provided, a default contract address is fetched from the Aelf blockchain. | | ||
| `contractName`| `string` | `"Contract"` | The name of the contract to be displayed. | | ||
| `rpcUrl` | `string` | `"https://explorer-test-side02.aelf.io/chain"` | The RPC URL to connect to the Aelf blockchain. | | ||
|
||
|
||
## Example Explanation | ||
|
||
The above example demonstrates how to use the **`ContractView`** component. You only need to pass in the contract's address, RPC URL, and optionally the contract name. | ||
|
||
## Smart Contract Interaction | ||
|
||
The **`ContractView`** component displays the available read and write methods from the given smart contract. Once loaded, the methods are grouped as follows: | ||
|
||
- **Read Methods:** These are functions you can call to read data from the contract without sending a transaction. | ||
- **Write Methods:** These are functions that will initiate a blockchain transaction to update the state of the contract. | ||
|
||
## Example with Wallet | ||
|
||
If you want to specify your own wallet, you can pass the **`wallet`** prop. If you don’t provide a wallet, the component will create a new wallet for you and interact with the blockchain using that. | ||
|
||
```typescript | ||
import React from "react"; | ||
import { ContractView } from "aelf-smartcontract-viewer"; | ||
import AElf from "aelf-sdk"; | ||
|
||
const App = () => { | ||
const wallet = AElf.wallet.getWalletByPrivateKey("YOUR_PRIVATE_KEY"); | ||
|
||
return ( | ||
<div> | ||
<ContractView | ||
wallet={wallet} | ||
address="your_smart_contract_address" | ||
rpcUrl="rpc_url" // i.e = https://explorer-test-side02.aelf.io/chain | ||
contractName="Smart Contract Name" | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; | ||
``` | ||
|
||
## Features | ||
|
||
- **Auto Wallet Creation:** If no wallet is provided, the component creates a new wallet. | ||
- **RPC URL Management:** Users can select different RPC URLs for connecting to different blockchain networks. | ||
- **Contract Method Interaction:** The component lists both read and write methods available on the contract, allowing for easy interaction. | ||
|
||
## Contributing | ||
|
||
We welcome contributions to this project. If you find any bugs or want to add new features, feel free to submit a pull request or open an issue on the [GitHub repository](https://github.com/RutvikGhaskataEalf/aelf-smartcontract-viewer). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "aelf-smartcontract-viewer", | ||
"version": "1.0.2", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"type": "module", | ||
"scripts": { | ||
"build": "npx rollup -c", | ||
"dev": "vite" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/AElfProject/create-aelf-dapp/tree/main/packages/aelf-smartcontract-viewer" | ||
}, | ||
"description": "A React component to view and interact with Aelf smart contracts", | ||
"keywords": [ | ||
"aelf", | ||
"smart contracts", | ||
"blockchain", | ||
"react", | ||
"contract viewer", | ||
"aelf-sdk", | ||
"dapp" | ||
], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@rollup/plugin-babel": "^6.0.4", | ||
"@rollup/plugin-typescript": "^12.1.0", | ||
"@rollup/plugin-url": "^8.0.2", | ||
"@types/loadable__component": "^5.13.9", | ||
"@types/react": "^18.3.10", | ||
"@vitejs/plugin-react": "^4.3.2", | ||
"postcss": "^8.4.47", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"rollup": "^4.22.5", | ||
"rollup-plugin-postcss": "^4.0.2", | ||
"tailwindcss": "^3.4.13", | ||
"tslib": "^2.7.0", | ||
"vite": "^5.4.8" | ||
}, | ||
"dependencies": { | ||
"@portkey/contracts": "^2.11.0-alpha.16", | ||
"@portkey/request": "^2.10.5", | ||
"aelf-sdk": "^3.4.15", | ||
"antd": "^5.21.2", | ||
"clsx": "^2.1.1", | ||
"query-string": "^7.1.3", | ||
"react-json-tree": "^0.19.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { defineConfig } from "rollup"; | ||
import typescript from "@rollup/plugin-typescript"; | ||
import url from '@rollup/plugin-url'; | ||
import postcss from 'rollup-plugin-postcss'; | ||
|
||
export default defineConfig({ | ||
input: "src/index.ts", | ||
output: { | ||
dir: "dist", | ||
format: "es", | ||
name: "npm-contract-viewer", | ||
}, | ||
external: [ | ||
'react', | ||
'react-dom', | ||
'antd', | ||
'@portkey/contracts', | ||
'@portkey/request', | ||
'aelf-sdk', | ||
'clsx', | ||
'copy-to-clipboard', | ||
'query-string', | ||
'react-json-tree' | ||
], | ||
plugins: [ | ||
typescript({ tsconfig: "tsconfig.json" }), | ||
url({ | ||
include: ["**/*.svg"], // Tell Rollup to include SVGs | ||
limit: 0, // No file size limit | ||
}), | ||
postcss({ | ||
extensions: ['.css'], // Specify that we are handling CSS files | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// src/assets.d.ts | ||
declare module '*.svg' { | ||
const content: string; | ||
export default content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from "react"; | ||
|
||
export const CopyIcon = ({ onClick }: { onClick: () => void }) => ( | ||
<svg | ||
stroke="currentColor" | ||
fill="currentColor" | ||
strokeWidth="0" | ||
viewBox="0 0 256 256" | ||
height="18px" | ||
width="18px" | ||
xmlns="http://www.w3.org/2000/svg" | ||
onClick={onClick} | ||
> | ||
<path d="M216,34H88a6,6,0,0,0-6,6V82H40a6,6,0,0,0-6,6V216a6,6,0,0,0,6,6H168a6,6,0,0,0,6-6V174h42a6,6,0,0,0,6-6V40A6,6,0,0,0,216,34ZM162,210H46V94H162Zm48-48H174V88a6,6,0,0,0-6-6H94V46H210Z"></path> | ||
</svg> | ||
); | ||
|
||
export const RightIcon = ({ className }: { className: string }) => ( | ||
<svg | ||
stroke="currentColor" | ||
fill="currentColor" | ||
strokeWidth="0" | ||
viewBox="0 0 24 24" | ||
height="18px" | ||
width="18px" | ||
xmlns="http://www.w3.org/2000/svg" | ||
className={className} | ||
> | ||
<path d="M13.22 19.03a.75.75 0 0 1 0-1.06L18.19 13H3.75a.75.75 0 0 1 0-1.5h14.44l-4.97-4.97a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215l6.25 6.25a.75.75 0 0 1 0 1.06l-6.25 6.25a.75.75 0 0 1-1.06 0Z"></path> | ||
</svg> | ||
); | ||
|
||
export const DownIcon = () => ( | ||
<svg | ||
width="10" | ||
height="10" | ||
viewBox="0 0 10 10" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g id="direction/down"> | ||
<g id="Union"> | ||
<path | ||
d="M4.99989 6.03477L1.85915 2.89404C1.81034 2.84522 1.73119 2.84522 1.68237 2.89404L1.24043 3.33598C1.19162 3.38479 1.19162 3.46394 1.24043 3.51276L4.77911 7.05143C4.90115 7.17347 5.09901 7.17347 5.22105 7.05143L8.75978 3.51232C8.80859 3.46351 8.80859 3.38436 8.75977 3.33555L8.31783 2.8936C8.26902 2.84479 8.18987 2.84479 8.14106 2.8936L4.99989 6.03477Z" | ||
fill="#252525" | ||
/> | ||
</g> | ||
</g> | ||
</svg> | ||
); | ||
|
||
export const AddIcon = () => ( | ||
<svg | ||
width="10" | ||
height="10" | ||
viewBox="0 0 10 10" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<g id="suggest/add"> | ||
<g id="Union"> | ||
<path | ||
d="M5.43747 8.78125C5.43747 8.85028 5.38151 8.90625 5.31247 8.90625H4.68747C4.61843 8.90625 4.56247 8.85029 4.56247 8.78125V5.43751H1.21875C1.14971 5.43751 1.09375 5.38154 1.09375 5.31251V4.68751C1.09375 4.61847 1.14971 4.56251 1.21875 4.56251H4.56247V1.21875C4.56247 1.14971 4.61843 1.09375 4.68747 1.09375H5.31247C5.38151 1.09375 5.43747 1.14971 5.43747 1.21875V4.56251H8.78125C8.85029 4.56251 8.90625 4.61847 8.90625 4.68751V5.31251C8.90625 5.38154 8.85029 5.43751 8.78125 5.43751H5.43747V8.78125Z" | ||
fill="#252525" | ||
/> | ||
</g> | ||
</g> | ||
</svg> | ||
); |
Oops, something went wrong.