npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ascai-trx

v1.3.9

Published

Ascai - smart contract analysis using AI

Downloads

13

Readme

ascai-trx

npm version

Overview

ascai-trx is a JavaScript library for enhancing the security of smart contract interactions on the Ethereum blockchain. It leverages AI-powered natural language processing (NLP) to provide an extra layer of security by analyzing smart contracts before transaction execution. This analysis helps users make informed decisions about whether to proceed with a contract interaction.

Installation

You can install ascai-trx using npm or yarn:

npm  install  ascai-trx

## OR

yarn  add  ascai-trx

Usage

To use ascai-trx in your project, follow these steps:

Import the Ascai component:

import  Ascai  from  "ascai-trx";

Create a state variable to store your contract data:

import  {  useState  }  from  "react";



const [data, setData]  =  useState({

contractAddress:  "0x8048ae8cDadA2A466B38679e41b42f613F3912F2",

signer:  "",  //  Set  your  signer

functionName:  "set",  //  The  function  you  want  to  call

inputValue:  "",  //  The  input  value  for  the  function

params:  {

value:  0,  //  Value  in  Wei

gasLimit:  100000,  //  Gas  limit  for  the  transaction

},

contractAbi:  storeMyNumberAbi,  //  Your  contract's ABI

});

Add the component:

<Ascai

contractAddress={data.contractAddress}

signer={data.signer}

functionName={data.functionName}

inputValue={data.inputValue}

params={data.params}

contractAbi={data.contractAbi}

/>

update your existing button with

<button type="submit" onClick={customFunction}></button>

Add this custome function to your component

const customFunction = () => {
    const btn = document.getElementById("ascai-btn");
    btn.click();
};

Now, when the user clicks the "Submit" button, a popup will open, showing the AI-powered NLP analysis of the smart contract. Users can review the analysis and decide whether to proceed with the contract interaction.

If the user chooses to proceed, the transaction will be executed using the specified contract data and function.

You can also handle the result of the transaction using event listeners or other mechanisms as needed.

Example

import React, { Children, useEffect, useState } from    "react";
import { sendTransactionDetails } from "ascai-trx";
import Ascai from "ascai-trx";
import storeMyNumberAbi from "./StoreMyNumber.json";
import { ethers } from "ethers";

function ContractInteractionForm() {
const [cdnEndpoint, setCdnEndpoint] = useState("");
const [result, setResult] = useState([]);
const [showPopup, setPopup] = useState(false);

const [data, setData] = useState({
contractAddress: "0x8048ae8cDadA2A466B38679e41b42f613F3912F2",
signer: "",
functionName: "set",
inputValue: "",
params: {
value: 0,
gasLimit: 100000,
},
contractAbi: storeMyNumberAbi,
});
const handleSendTransaction = async () => {
try {
if (window.ethereum) {
const ethereumProvider = new ethers.providers.Web3Provider(
    window.ethereum
);
await window.ethereum.enable(); // Request user permission to connect
let signer = ethereumProvider.getSigner();
console.log(signer);
setData({
    ...data,
    signer: signer,
    inputValue: [25],
});
}
} catch (error) {
console.log("error", error);
}
};

const customFunction = () => {
const btn = document.getElementById("ascai-btn");
btn.click();
};
useEffect(() => {
handleSendTransaction();
}, []);
return (
<div>
{/* {result ? result : null} */}
<button type="submit" onClick={customFunction}>
Register
</button>
<Ascai
contractAddress={data.contractAddress}
signer={data.signer}
functionName={data.functionName}
inputValue={data.inputValue}
params={data.params}
contractAbi={data.contractAbi}
/>
</div>
);
}

export default ContractInteractionForm;

Conclusion

Congratulations! You've successfully integrated and used the ascai-trx library in your project. This added security layer, powered by AI analysis, enhances the safety of your smart contract interactions. If you have any questions or encounter any issues, please refer to the documentation or reach out to our support team.

For more information and detailed documentation, visit our GitHub repository.

This example demonstrates how to integrate ascai-trx into a React component. Users can now analyze the smart contract using AI-powered NLP before proceeding with the transaction, adding an extra layer of security to their interactions.