Skip to content

Commit c1c3e38

Browse files
committed
Add example to call System.RemarkWithEvent in an Eth transaction.
1 parent ed0f8a4 commit c1c3e38

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
use jsonrpsee::http_client::HttpClientBuilder;
18+
use pallet_revive::evm::{Account, ReceiptInfo};
19+
use pallet_revive_eth_rpc::example::TransactionBuilder;
20+
use sp_core::H160;
21+
use std::sync::Arc;
22+
23+
#[tokio::main]
24+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
25+
let tx_payload: Vec<u8> = vec![
26+
0x00, // System pallet index.
27+
0x07, // Remark With Event call index.
28+
0x10, // Compact-encoded length of the remark (16).
29+
0x54, 0x45, 0x53, 0x54, // Remark 'T', 'E', 'S', 'T'
30+
];
31+
32+
let client = Arc::new(HttpClientBuilder::default().build("http://localhost:8545")?);
33+
34+
let alith = Account::default();
35+
// Revive pallet address.
36+
let dest = H160::from_slice(&hex::decode("6d6f646c70792f70616464720000000000000000")?);
37+
38+
println!("\n\n=== Eth calling System.Remark ===\n\n");
39+
40+
let tx = TransactionBuilder::new(&client)
41+
.signer(alith)
42+
.input(tx_payload)
43+
.to(dest)
44+
.send()
45+
.await?;
46+
println!("Transaction hash: {:?}", tx.hash());
47+
48+
let ReceiptInfo {
49+
block_number,
50+
gas_used,
51+
status,
52+
..
53+
} = tx.wait_for_receipt().await?;
54+
println!("Receipt: ");
55+
println!("- Block number: {block_number}");
56+
println!("- Gas used: {gas_used}");
57+
println!("- Success: {status:?}");
58+
59+
Ok(())
60+
}

0 commit comments

Comments
 (0)