logoAcademy

Interact with a Precompile

Learn about why you should utilize Precompiles in your smart contracts.

So let's get to it and interact with a precompile on the C-Chain of your local network. The SHA256 precompile is already available on the C-Chain.

Call Precompile from Foundry

In this example, we will call the SHA256 precompile to generate hash of the input string.

Precompile Address: 0x0000000000000000000000000000000000000002

cast call --rpc-url local-c --private-key $PK 0x0000000000000000000000000000000000000002 "run(string)(bytes32)" "test"

You should see a bytes32 hash of the input string test as the output.

0xa770b926e13a31fb823282e9473fd1da9e85afe23690336770c490986ef1b1fc

On this page