1/5
## Calling Functions Using "raw" Hexdata We can call any other smart contract from our contract using raw hex data without using the ABI library. To do this, we need to define our function with the following: ```python @external def call_function_directly(address_to_call: address, address: address, new_amount: uint256, update_address: address) -> Bytes[32]: success: bool = False response: Bytes[32] = b'' success, response = raw_call( address_to_call, abi.encode( update_address, new_amount, method_id='transfer(address,uint256)' ), max_outsize=32, revert_on_failure=False ) assert success return response ``` In this example, we: 1. Define a function called `call_function_directly` with the following parameters: * `address_to_call`: the address of the contract we are calling. * `address`: the address to send the tokens to. * `new_amount`: the amount of tokens to send. * `update_address`: the address to update. 2. We set the `success` variable to `False` and the `response` variable to an empty bytes object. 3. We use the `raw_call` function with the following parameters: * `address_to_call`: the address of the contract we are calling. * `abi.encode`: encoding our data (we use the `abi` library to encode our data). * `max_outsize=32`: the maximum size of the response. * `revert_on_failure=False`: set to `False` in case of failure. 4. We then assert that the `success` variable is `True` and return the `response`. By using the `raw_call` function, we can directly call any other smart contract without using the ABI library. This can be useful for interacting with contracts that do not have an ABI available.
A comprehensive guide to calling Solidity smart contracts using raw hex data in Viper. This lesson shows how to generate raw hex data to call a transfer function, and then how to use that data to directly interact with a smart contract.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
How to build a DeFi stablecoin and customized NFT
How to deploy your smart contract on ZKsync with Moccasin
Advanced testing techniques like stateful and stateless Python fuzzing
How to write algorithmic trading scripts in Python
Hashing signatures, proxies, delegate calls, upgradable contracts, random numbers, and more!
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on February 4, 2025
Duration: 2h 21min
Duration: 1h 58min
Duration: 2h 55min
Duration: 1h 55min
Duration: 46min
Course Overview
About the course
How to build a DeFi stablecoin and customized NFT
How to deploy your smart contract on ZKsync with Moccasin
Advanced testing techniques like stateful and stateless Python fuzzing
How to write algorithmic trading scripts in Python
Hashing signatures, proxies, delegate calls, upgradable contracts, random numbers, and more!
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on February 4, 2025