Skip to content

Instantly share code, notes, and snippets.

@brenzi
Last active April 2, 2019 21:56
Show Gist options
  • Save brenzi/6bd6a430806a85e2edae4b7fd82f9d83 to your computer and use it in GitHub Desktop.
Save brenzi/6bd6a430806a85e2edae4b7fd82f9d83 to your computer and use it in GitHub Desktop.
generating and sending an extrinsic using ws
// send a transaction
let nonce = 0;
let tx = Transfer {
amount: 42,
nonce,
from: AccountKeyring::Alice.into(),
to: AccountKeyring::Bob.into(),
};
let signature = AccountKeyring::from_public(&tx.from).unwrap().sign(&tx.encode()).into();
let xt = Extrinsic::Transfer(tx, signature).encode();
let mut xthex = hex::encode(xt);
xthex.insert_str(0, "0x");
let jsonreq = json!({
"method": "author_submitAndWatchExtrinsic",
"params": [xthex], // params,
"jsonrpc": "2.0",
"id": self.id.to_string(),
});
println!("sending extrinsic: {}", jsonreq.to_string());
self.out.send(jsonreq.to_string()).unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment