Bevy meets Metamask! This plugin is only supported in wasm target. The core concept of the plugin is a communication via a request event and the corresponding response event. Whenever you send a request event, IoTaskPool
handles the request and then send the response event.
- Implement a request event
E
which implementsMetamaskRequestEvent
- Implement corresponding response event
E::ResponseEvent (as MetamaskRequestEvent)
- Add
MetamaskPlugin<E>
struct EthereumRequestEvent;
struct EthereumResponseEvent(String);
impl bevy_metamask::MetamaskRequestEvent for EthereumRequestEvent {
type ResponseEvent = EthereumResponseEvent;
fn to_req(&self) -> bevy_metamask::MetamaskRequest {
bevy_metamask::MetamaskRequest::BlockNumber(bevy_metamask::BlockNumber)
}
fn from_resp(resp: bevy_metamask::MetamaskResponse) -> Self::ResponseEvent {
match resp {
bevy_metamask::MetamaskResponse::BlockNumber(block_number) => {
EthereumResponseEvent(block_number)
}
_ => unreachable!(),
}
}
}
fn main() {
// ...
app.add_plugin(MetamaskPlugin::<EthereumRequestEvent>::new())
// ...
}
In order to separate response events such as Call
to A contract and Call
to B contract, you should define two dintinct events and add two plugins.
For further information, please see an example.
Compatibility of bevy_metamask
versions:
bevy_metamask |
bevy |
---|---|
0.1 |
0.9 |
- | - |