MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / code

Method code

web3/src/contract.rs:70–81  ·  view source on GitHub ↗

Get the contract code for an address See https://eth.wiki/json-rpc/API#eth_getCode # Examples ```ignore let web3 = web3::Web3::new("http://127.0.0.1:8545").unwrap(); let contract = include_bytes!("./../../contracts/artifacts/contracts/ERC20.sol/RustCoinToken.json").to_vec(); let tx_hash = web3.deploy(account, &contract).await.unwrap(); let receipt = web3.transaction_receipt(tx_hash).await.unwra

(
        &self,
        address: Address,
        block_number: Option<BlockNumber>,
    )

Source from the content-addressed store, hash-verified

68 /// assert!(code.is_ok());
69 /// ```
70 pub async fn code(
71 &self,
72 address: Address,
73 block_number: Option<BlockNumber>,
74 ) -> Result<Vec<u8>> {
75 let block_number = Web3::get_hex_blocknumber(block_number);
76 let params = rpc_params![to_hex(address), block_number];
77 let response = self.send_rpc("eth_getCode", params).await?;
78 let code: Vec<u8> = serde_json::from_value(response)?;
79
80 Ok(code)
81 }
82}
83
84#[cfg(test)]

Callers 1

it_gets_a_contract_codeFunction · 0.80

Calls 1

send_rpcMethod · 0.80

Tested by

no test coverage detected