Skip to content

Commit

Permalink
server fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Oct 9, 2024
1 parent 8bf82f2 commit d931a80
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 6 deletions.
59 changes: 59 additions & 0 deletions substrate/frame/revive/rpc/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Start the node

Start the kitchensink node

```bash
RUST_LOG="error,evm=debug,sc_rpc_server=info,runtime::revive=debug" cargo run --bin substrate-node -- --dev
```

## Start the RPC server

This command starts the Ethereum JSON-RPC server, by default it runs on `localhost:9090`

```bash
RUST_LOG="info,eth-rpc=debug" cargo run -p pallet-revive-eth-rpc --features dev
```

## Send a transaction using provided examples

You can run one of the examples from the `examples` directory to send a transaction to the node.

```bash
RUST_LOG="info,eth-rpc=debug" cargo run -p pallet-revive-eth-rpc --features example --example deploy
```

## Interact with the node using MetaMask & Ether.js

Start the Ether.js demo server, and open the demo Ether.js web page at `http://localhost:3000`

```bash
cd substrate/frame/revive/rpc/demo && yarn && yarn dev
```

### Configure MetaMask

You can use the following instructions to setup [MetaMask](https://metamask.io) with the local chain.

> Note: When you interact with MetaMask and restart the chain, you need to clear the activity tab (Settings > Advanced > Clear activity tab data)
> See [here](https://support.metamask.io/managing-my-wallet/resetting-deleting-and-restoring/how-to-clear-your-account-activity-reset-account) for more info on how to reset the account activity.
#### Add a new network

To interact with the local chain, you need to add a new network in [MetaMask](https://metamask.io).
See [here](https://support.metamask.io/networks-and-sidechains/managing-networks/how-to-add-a-custom-network-rpc/#adding-a-network-manually) for more info on how to add a custom network.

Make sure the node and the rpc server are started, and use the following settings to configure the network (MetaMask > Networks > Add a network manually):

- Network name: KitchenSink
- RPC URL: <http://localhost:9090>
- Chain ID: 420420420
- Currency Symbol: `DEV`

#### Import Dev account

You will need to import the following account that is endowed with some balance at genesis to interact with the chain.
See [here](https://support.metamask.io/managing-my-wallet/accounts-and-addresses/how-to-import-an-account/) for more info on how to import an account.

- Account: `0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac`
- Private Key: `5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133`

2 changes: 0 additions & 2 deletions substrate/frame/revive/rpc/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@polkadot/types": "^12.2.1",
"@polkadot/util": "^13.0.2",
"ethers": "^6.13.1"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/revive/rpc/demo/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="https://polkadot.com/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Deploy Contract with MetaMask</title>
<style>
Expand Down
13 changes: 10 additions & 3 deletions substrate/frame/revive/rpc/demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BrowserProvider, Contract, ContractFactory, JsonRpcSigner, parseEther, encodeRlp, AddressLike } from 'ethers';
import { hexToU8a } from '@polkadot/util';
import { BrowserProvider, Contract, ContractFactory, JsonRpcSigner, parseEther, encodeRlp, AddressLike, getBytes } from 'ethers';

document.addEventListener('DOMContentLoaded', async () => {
if (typeof window.ethereum == 'undefined') {
Expand Down Expand Up @@ -56,11 +55,19 @@ document.addEventListener('DOMContentLoaded', async () => {
await call(address);
});

const code = getBytes('0x606060');
const args = new Uint8Array();
const rlpEncoded = encodeRlp([ code, args ]);
console.log("RLP encoded:", rlpEncoded);

async function deploy() {
console.log('Deploying contract...');
const code = hexToU8a('0x50564d0001010424009000022363616c6cdeadbeef63616c6c5f6e657665726465706c6f797365616c5f72657475726e041001000000007365616c5f72657475726e051b03000a63616c6c5f6e6576657204066465706c6f79060463616c6c062c06011f000406081b1c06100408130013000211fc03100408040001040904040706100a05004e13005129a4b800');

const code = getBytes('0x50564d0001010424009000022363616c6cdeadbeef63616c6c5f6e657665726465706c6f797365616c5f72657475726e041001000000007365616c5f72657475726e051b03000a63616c6c5f6e6576657204066465706c6f79060463616c6c062c06011f000406081b1c06100408130013000211fc03100408040001040904040706100a05004e13005129a4b800');
const args = new Uint8Array()
const bytecode = encodeRlp([ code, args ]);
console.log(bytecode);

const contractFactory = new ContractFactory([], bytecode, signer);

try {
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/revive/rpc/examples/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ async fn main() -> anyhow::Result<()> {
println!("\n\n=== Deploying contract ===\n\n");

let input = rlp::encode(&input).to_vec();
println!("Deploying contract with input: 0x{}", hex::encode(&input));

let nonce = client.get_transaction_count(account.address(), BlockTag::Latest.into()).await?;
let hash = account.send_transaction(&client, U256::zero(), input.into(), None).await?;

Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/revive/rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl Client {
Ok(result)
}

/// Dry run a transaction and returns the [`DryRunInfo`] for the transaction.
/// Dry run a transaction and returns the [`EthContractResult`] for the transaction.
pub async fn dry_run(
&self,
tx: &GenericTransaction,
Expand Down Expand Up @@ -700,6 +700,7 @@ impl Client {
transactions_root: header.extrinsics_root,
number: header.number.into(),
timestamp: timestamp.into(),
difficulty: Some(0u32.into()),
gas_limit,
logs_bloom: Bytes256([0u8; 256]),
receipts_root: header.extrinsics_root,
Expand Down

0 comments on commit d931a80

Please sign in to comment.