## Compile Contract First let's compile contract using solidity compiler. ```bash echo 'contract Storage { uint pos0; mapping(address => uint) pos1; function Storage_func() public {  pos0 = 1234;  pos1[msg.sender] = 5678;  } }' | solc --bin - ``` Generated Bytecode: ``` 6080604052348015600e575f80fd5b5060b680601a5f395ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c8063fcff4c0814602a575b5f80fd5b60306032565b005b6104d25f8190555061162e60015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f208190555056fea2646970667358221220615d2c9c894f2d6ab072b64f478ea2763653cb8223893c4b22e91ffd8c3c817864736f6c63430008190033 ``` <details> <summary>Contract </summary> <p> ```js // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.8.2 <0.9.0; /** * @title Storage * @dev Store & retrieve value in a variable * @custom:dev-run-script ./scripts/deploy_with_ethers.ts */ contract Storage { uint pos0; mapping(address => uint) pos1; function Storage_func() public { pos0 = 1234; pos1[msg.sender] = 5678; } } ``` </p> </details> ## Deploy contract ```bash curl --data '{"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "data": "0x6080604052348015600e575f80fd5b5060b680601a5f395ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c8063fcff4c0814602a575b5f80fd5b60306032565b005b6104d25f8190555061162e60015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f208190555056fea2646970667358221220615d2c9c894f2d6ab072b64f478ea2763653cb8223893c4b22e91ffd8c3c817864736f6c63430008190033"}' -H "Content-Type:application/json" localhost:3000/eth/tx -X POST ``` Send Transaction for executing function `Storage_func`. > Note: We are updating state of Ethereum on calling this function. Therefore, calling this function should be done through `eth_sendTransaction` and not `eth_call`. - Through JSON RPC API ```bash curl --data '{"jsonrpc":"2.0","method": "eth_sendTransaction", "params":[{"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "to": "0x5fbdb2315678afecb367f032d93f642f64180aa3", "data": "0xfcff4c08"}], "id": 8}' -H "Content-Type: application/json" localhost:8545 ``` OR - Through ethRPCtoREST ```bash curl --data '{"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "to": "0x5fbdb2315678afecb367f032d93f642f64180aa3","data": "Storage_func()"}' -H "Content-Type: application/json" localhost:3000/eth/tx -X POST ``` ## Read storage from contract Get `pos0` value from contract with contract address `0x5fbdb2315678afecb367f032d93f642f64180aa3` at following path. ``` http://localhost:3000/eth/storage/0x5fbdb2315678afecb367f032d93f642f64180aa3/0/latest ``` Get value from map stored in `pos1` using caller address (`msg.sender`) as key in the map. ``` http://localhost:3000/eth/storage/0x5fbdb2315678afecb367f032d93f642f64180aa3/1/latest?map=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 ```