Last active
April 2, 2019 21:56
-
-
Save brenzi/6bd6a430806a85e2edae4b7fd82f9d83 to your computer and use it in GitHub Desktop.
generating and sending an extrinsic using ws
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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