Skip to content

dotrungkien/eth-client-multilang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Contract client in multi languages

  • JS: use ethers.js
  • Rust: use ethers-rs
  • Python: use web3.py

Prerequisite

  • Foundry
  • Ethers-rs
  • Ethers.js
  • web3.py

Compile & Deploy contract

  • run a local node:
anvil
ETH_FROM=<account address from anvil>
  • deploy contract to local net
cd contracts/
forge create src/Contract.sol:SimpleStorage --constructor-args 123 --unlocked --from $ETH_FROM
SIMPLE_STORAGE=<your deployed address>
  • test functionality
cast --to-dec $(cast call $SIMPLE_STORAGE "get()")
> 123

cast send $SIMPLE_STORAGE "set(uint256)" 321 --from $ETH_FROM

cast --to-dec $(cast call $SIMPLE_STORAGE "get()")
> 321

Copy ABIs

  • Copy abi from contracts/out/Contract.sol/SimpleStorage.json to clients/abis/SimpleStorage.json

Run Client

Rust

cd clients/rust/

cargo run

JS

cd clients/js/
yarn
node index.js

Python

cd clients/py/

# recommend to use virtual env to run
pip install -r requirements.txt
python main.py