
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@cogitojs/cogito-ethereum-react
Advanced tools
Provides a React component that allows interaction with smart contracts on an Ethereum blockchain using the Cogito app. It provides the same functionality as the Cogito Ethereum package in a React friendly way.
Add @cogitojs/cogito-ethereum-react
as a dependency:
yarn add @cogitojs/cogito-ethereum-react
and import it:
import { CogitoEthereumReact } from '@cogitojs/cogito-ethereum-react'
The CogitoEthereumReact
component accepts the following props:
prop name | description |
---|---|
contractsBlobs | Array of contracts JSON blobs - see Working with Contracts for more details. |
channelId | identifier of the Telepath channel. If omitted a new random channel id will be created. |
channelKey | a symmetric key of the Telepath channel. If omitted a new random key will be created. |
appName | the name of the app. Cogito app shows the appName when requesting user signature. |
onTelepathChanged | function to be called when the telepath channel has been updated. Provides an object { channelId, channelKey, appName } as an argument. |
render | render prop - a function that will be called every time the component is updated. It provides { cogitoWeb3, telepathChannel, contractsProxies, newChannel } as an argument, where cogitoWeb3 is an instance of Web3 that uses CogitoProvider, telepathChannel is an instance of Telepath, and contractsProxies is an object holding the references to contracts proxies corresponding to the provided contracts JSON blobs (see Working with Contracts for details). newChannel is a function to change the current channel to a new one. This function will trigger calling the render prop (or child) function, which means the whole tree below it will be (re)rendered. If this prop is present, it will take precedence over the children . |
The example below illustrates how to use the CogitoEthereumReact
component:
import { CogitoEthereumReact } from '@cogitojs/cogito-ethereum-react'
import { SimpleStorage } from '@cogitojs/demo-app-contracts'
class Main extends React.Component {
web3IsReady = ({cogitoWeb3, telepathChannel, contractsProxies}) => {
return (cogitoWeb3 && telepathChannel && contractsProxies.SimpleStorage)
}
onTelepathChanged = ({ channelId, channelKey, appName }) => {
console.log('Telepath channel changed:')
console.log(`channelId: ${channelId}`)
console.log(`channelKey: ${channelKey}`)
console.log(`appName: ${appName}`)
}
render () {
return (
<CogitoEthereumReact contractsBlobs={[SimpleStorage()]}
channelId={channelId}
channelKey={channelKey}
appName='Cogito Demo App'
onTelepathChanged={this.onTelepathChanged}
>
{web3Props => {
if (this.web3IsReady(web3Props)) {
return (
<div>
<p>Ready!</p>
<button onClick={web3Props.newChannel()}>
Change channel
</button>
</div>
)
} else {
return (
<p>Please wait...</p>
)
}
}}
</CogitoEthereumReact>
)
}
}
export { Main }
If you prefer using render
prop, the render
method would look like this:
render () {
return (
<CogitoEthereumReact contractsBlobs={[SimpleStorage()]}
channelId={channelId}
channelKey={channelKey}
appName='Cogito Demo App'
onTelepathChanged={this.onTelepathChanged}
render={web3Props => {
if (this.web3IsReady(web3Props)) {
return (
<div>
<p>Ready!</p>
<button onClick={web3Props.newChannel()}>
Change channel
</button>
</div>
)
} else {
return (
<p>Please wait...</p>
)
}
}} />
)
}
FAQs
Cogito Ethereum React library
The npm package @cogitojs/cogito-ethereum-react receives a total of 1 weekly downloads. As such, @cogitojs/cogito-ethereum-react popularity was classified as not popular.
We found that @cogitojs/cogito-ethereum-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.