-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(transactions): transaction examples #4
Conversation
Pulled in the latest upstream changes and made a few slight stylistic changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if we can make this a bit simpler after merging, either by flattening or simplifying the example.
When we look at flattening the repo structure I would like to have a dedicated folder (fixtures
?) to store these kind of assets in. That allows for re-use across examples.
async fn main() -> Result<()> { | ||
let (provider, _anvil) = init(); | ||
|
||
let call = latestAnswerCall {}.abi_encode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no fields should not require {}
imo -- @DaniPopes, also in this case it could be made const
but doubt it fits in abstraction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must be an instance, in order to decode it, so this is fine imo
|
||
fn init() -> (HttpProvider<Ethereum>, AnvilInstance) { | ||
let anvil = Anvil::new().fork("https://eth.llamarpc.com").spawn(); | ||
let url = anvil.endpoint().parse().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make anvil return Url
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that would be ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add this as a new function?
fn endpoint_url?
fn usd_value(amount: U256, price_usd: U256) -> Result<f64> { | ||
let base: U256 = U256::from(10).pow(U256::from(ETH_DECIMALS)); | ||
let value: U256 = amount * price_usd / base; | ||
let usd_price_decimals: u8 = 8; | ||
let f: String = format_units(value, usd_price_decimals)?; | ||
Ok(f.parse::<f64>()?) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we wanna add this as a general helper? :P
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let (provider, _anvil) = init(); | ||
let hash = fixed_bytes!("97a02abf405d36939e5b232a5d4ef5206980c5a6661845436058f30600c52df7"); // Hash of the tx we want to trace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont love fixed_bytes, too long, do we have an alias for it
(HttpProvider::new(RpcClient::new(http, true)), anvil) | ||
} | ||
|
||
async fn deploy_token_contract( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with ERC20Example::deploy(...)
..Default::default() | ||
}; | ||
|
||
let pending_tx = provider.send_transaction(transfer_tx).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't this take a block tag? maybe no longer in the new api
let input = ERC20Example::transferCall { to, amount: U256::from(100) }.abi_encode(); | ||
// Convert to Bytes | ||
let input = Bytes::from(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should abi_encode always return Bytes maybe? maybe not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few more pedantic nits
async fn main() -> Result<()> { | ||
let (provider, _anvil) = init(); | ||
|
||
let call = latestAnswerCall {}.abi_encode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must be an instance, in order to decode it, so this is fine imo
|
||
fn init() -> (HttpProvider<Ethereum>, AnvilInstance) { | ||
let anvil = Anvil::new().fork("https://eth.llamarpc.com").spawn(); | ||
let url = anvil.endpoint().parse().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add this as a new function?
fn endpoint_url?
Added the following examples
decode_input
transfer_eth
transfer_erc20
trace_transaction
trace_call
- Uses trace_call as debug_traceCall is pending implementationgas_price_usd