Struct reba_client::client::RelayClient
source · pub struct RelayClient { /* private fields */ }
Implementations§
source§impl RelayClient
impl RelayClient
sourcepub fn new(
c_chain_addr: Address,
private_key: &SecretKey
) -> Result<Self, RelayClientError>
pub fn new(
c_chain_addr: Address,
private_key: &SecretKey
) -> Result<Self, RelayClientError>
Examples found in repository?
examples/stream_tx.rs (line 31)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
fn main()
{
let pk_str = get_env("PK");
let private_key_bytes: &[u8] = pk_str.as_bytes();
let sk = SecretKey::from_slice(&decode(private_key_bytes).unwrap()).unwrap();
let pk = SecretKeyRef::new(&sk);
let address = pk.address();
let mut client = RelayClient::new(address, &pk).unwrap();
loop
{
let transaction = client.read_tx();
match transaction
{
Some(tx) =>
{
println!("Chain ID: {}", tx.chain_id());
println!("Nonce: {}", tx.nonce());
println!("Value: {}", tx.value());
println!("To: {}", tx.tx_to());
println!("From: {}", tx.tx_from());
println!("Input: {:?}", tx.input());
println!("Gas Limit: {}", tx.gas_limit());
println!("Gas Price: {:?}", tx.gas());
println!("TX Type: {:?}", tx.tx_type());
}
None =>
{
println!("Could not connect to Relay. Are you registered?");
exit(1);
}
}
}
}
More examples
examples/send_tx.rs (line 45)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
async fn main()
{
// New HTTP provider. The provider is used to get information needed
// to send a valid TX when sending via the Relay.
let provider = Http::new(AVAX_API_URL).unwrap();
// New Web3 instance using the HTTP provider
let web3 = Web3::new(provider);
let pk_str = get_env("PK");
let private_key_bytes: &[u8] = pk_str.as_bytes();
let sk = SecretKey::from_slice(&decode(private_key_bytes).unwrap()).unwrap();
let pk = SecretKeyRef::new(&sk);
let address = pk.address();
let mut client = RelayClient::new(address, &pk).unwrap();
let tx = TransactionParameters { value: 0.into(),
nonce: None,
to: Some(address),
chain_id: 43114.into(), // Cam said this may fix it, still nothing.
..Default::default() };
let signed_tx = match web3.accounts().sign_transaction(tx, &sk).await
{
Ok(signed_tx) => signed_tx,
Err(e) =>
{
println!("Error signing transaction: {:?}", e);
exit(1);
}
};
println!("Signed tx hash: {:x?}", signed_tx.transaction_hash);
// this is not working. TX sends successfully, however it doesn't
// get to the nodes. Does not appear on snowtrace.
match client.send_tx(signed_tx)
{
Ok(_) => println!("Sent transaction successfully."),
Err(e) =>
{
println!("Error sending transaction: {:?}", e);
exit(1);
}
};
}
sourcepub fn read_tx(&mut self) -> Option<Transaction>
pub fn read_tx(&mut self) -> Option<Transaction>
Examples found in repository?
examples/stream_tx.rs (line 35)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
fn main()
{
let pk_str = get_env("PK");
let private_key_bytes: &[u8] = pk_str.as_bytes();
let sk = SecretKey::from_slice(&decode(private_key_bytes).unwrap()).unwrap();
let pk = SecretKeyRef::new(&sk);
let address = pk.address();
let mut client = RelayClient::new(address, &pk).unwrap();
loop
{
let transaction = client.read_tx();
match transaction
{
Some(tx) =>
{
println!("Chain ID: {}", tx.chain_id());
println!("Nonce: {}", tx.nonce());
println!("Value: {}", tx.value());
println!("To: {}", tx.tx_to());
println!("From: {}", tx.tx_from());
println!("Input: {:?}", tx.input());
println!("Gas Limit: {}", tx.gas_limit());
println!("Gas Price: {:?}", tx.gas());
println!("TX Type: {:?}", tx.tx_type());
}
None =>
{
println!("Could not connect to Relay. Are you registered?");
exit(1);
}
}
}
}
sourcepub fn send_tx(&mut self, tx: SignedTransaction) -> Result<(), RelayClientError>
pub fn send_tx(&mut self, tx: SignedTransaction) -> Result<(), RelayClientError>
Examples found in repository?
examples/send_tx.rs (line 67)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
async fn main()
{
// New HTTP provider. The provider is used to get information needed
// to send a valid TX when sending via the Relay.
let provider = Http::new(AVAX_API_URL).unwrap();
// New Web3 instance using the HTTP provider
let web3 = Web3::new(provider);
let pk_str = get_env("PK");
let private_key_bytes: &[u8] = pk_str.as_bytes();
let sk = SecretKey::from_slice(&decode(private_key_bytes).unwrap()).unwrap();
let pk = SecretKeyRef::new(&sk);
let address = pk.address();
let mut client = RelayClient::new(address, &pk).unwrap();
let tx = TransactionParameters { value: 0.into(),
nonce: None,
to: Some(address),
chain_id: 43114.into(), // Cam said this may fix it, still nothing.
..Default::default() };
let signed_tx = match web3.accounts().sign_transaction(tx, &sk).await
{
Ok(signed_tx) => signed_tx,
Err(e) =>
{
println!("Error signing transaction: {:?}", e);
exit(1);
}
};
println!("Signed tx hash: {:x?}", signed_tx.transaction_hash);
// this is not working. TX sends successfully, however it doesn't
// get to the nodes. Does not appear on snowtrace.
match client.send_tx(signed_tx)
{
Ok(_) => println!("Sent transaction successfully."),
Err(e) =>
{
println!("Error sending transaction: {:?}", e);
exit(1);
}
};
}