MCPcopy Create free account
hub / github.com/ChainSafe/Delorean-Protocol / main

Function main

fendermint/rpc/examples/transfer.rs:75–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73/// See the module docs for how to run.
74#[tokio::main]
75async fn main() {
76 let opts: Options = Options::parse();
77
78 tracing_subscriber::fmt()
79 .with_max_level(opts.log_level())
80 .init();
81
82 let client = FendermintClient::new_http(opts.url, None).expect("error creating client");
83
84 let sk =
85 SignedMessageFactory::read_secret_key(&opts.secret_key).expect("error reading secret key");
86
87 let pk = sk.public_key();
88
89 let f1_addr = Address::new_secp256k1(&pk.serialize()).expect("valid public key");
90 let f410_addr = Address::from(EthAddress::from(pk));
91
92 // Query the account nonce from the state, so it doesn't need to be passed as an arg.
93 let sn = sequence(&client, &f410_addr)
94 .await
95 .expect("error getting sequence");
96
97 // Query the chain ID, so it doesn't need to be passed as an arg.
98 let chain_id = client
99 .state_params(FvmQueryHeight::default())
100 .await
101 .expect("error getting state params")
102 .value
103 .chain_id;
104
105 let mf = SignedMessageFactory::new(sk, f410_addr, sn, ChainID::from(chain_id));
106
107 let mut client = client.bind(mf);
108
109 let res = TxClient::<TxCommit>::transfer(
110 &mut client,
111 f1_addr,
112 TokenAmount::from_whole(1),
113 GAS_PARAMS.clone(),
114 )
115 .await
116 .expect("transfer failed");
117
118 assert!(res.response.check_tx.code.is_ok(), "check is ok");
119 assert!(res.response.tx_result.code.is_ok(), "deliver is ok");
120 assert!(res.return_data.is_some());
121}
122
123/// Get the next sequence number (nonce) of an account.
124async fn sequence(client: &impl QueryClient, addr: &Address) -> anyhow::Result<u64> {

Callers

nothing calls this directly

Calls 10

parseFunction · 0.85
read_secret_keyFunction · 0.85
transferFunction · 0.85
bindMethod · 0.80
sequenceFunction · 0.70
initMethod · 0.45
log_levelMethod · 0.45
public_keyMethod · 0.45
serializeMethod · 0.45
state_paramsMethod · 0.45

Tested by

no test coverage detected