Skip to content

Instantly share code, notes, and snippets.

@thekaleidoscope
Last active December 29, 2021 07:32
Show Gist options
  • Save thekaleidoscope/8d3c77e7fedb3095f5b79b10810e5253 to your computer and use it in GitHub Desktop.
Save thekaleidoscope/8d3c77e7fedb3095f5b79b10810e5253 to your computer and use it in GitHub Desktop.

First things first

  • $ git clone https://github.com/hyperledger/sawtooth-seth
  • $ cd sawtooth-seth

To get official latest docs

  • Build with $ docker build . -f docs/Dockerfile -t seth-build-docs
  • Run with $ docker run -v $(pwd)/docs:/project/sawtooth-seth/docs seth-build-docs

It takes painfully long time and might file at times, However process gets a lot fast after it completes.

  • $ docker-compose up --build

Returning dev

  • $ docker-compose up not $ docker-compose -f xxx up --force or something similar.


Testing connection

  • $ curl http://0.0.0.0:8080/blocks
  • $ curl -d '{"jsonrpc": "2.0", "method": "eth_blockNumber", "id": 1}' -H "Content-Type: application/json" localhost:3030

Note: If the first passed and second doesn't, it means the seth-rpc failed to start

Follow :

  • Easy Method: Open docker-compose.yaml and docker-compose-installed.yaml and make changes to match the ones at here
  • What changed?
    • In docker-compose.yaml
      • A common volumn created for both seth-rpc and seth-cli by added sawtooth:/root/.sawtooth to volumn service of both seth-rpc and seth-cli, adding a volumn sawtooth in along with service.
      • expose port 3030 explictly for seth-rpc and enclosing '3030:3030' in ports
      • Adding proxy args
        • http_proxy
        • https_proxy
        • no_proxy
      • Remove seth init http://rest-api:8080 && from seth-rpc around 131 line.
    • In docker-compose-installed.yaml
      • Add proxy args similar to above
  • Rebuild the docker $ docker-compose up --build


Creating account

  • Open a new terminal

  • $ docker exec -it seth-cli bash

  • # openssl ecparam -genkey -name secp256k1 | openssl ec -out <filename>.pem -aes128

  • # seth account import <filename>.pem <alias>

    • Note: The alias will be used for refering the account in future. Located at ~/.sawtooth/keys
  • # seth account create --nonce=0 --wait <alias>

  • verify the existance of account

    • # seth show account {address}
  • Connect with rest-api seth init http://rest-api:8008



Verify the account can be accessed through seth-rpc

  • Open up a new terminal
  • $ docker exec -it seth-rpc bash
  • ls ~/.sawtooth/keys -al.

If you don't find the file ensure you made the changes as shown in above Note and rebuild the docker images

  • Close the terminal


Connect, import, unlock account for seth-rpc

  • Open a new terminal
  • $ docker exec -it seth-rpc bash
  • $ seth-rpc --connect tcp://validator:4004 --bind 0.0.0.0:3030 --unlock <alias>.

It goes into listening mode, let it be

Note: If the alias failed to be unlocked

Follow:

  • It means the key file of alias was not found
  • Easy Soln: Make changes to rpc/src/accounts.rs and rpc/comp_seth_rpc.yaml as in here
  • Rebuild the docker images by $ docker compose up --build

  • Open a new terminal

  • Test if your account is recognized by ethAccounts

    • $ curl -d '{"jsonrpc": "2.0", "method": "eth_accounts", "id": 2, "params": []}' -H "Content-Type: application/json" localhost:3030.

    If the result is [], recheck the connections and make sure all the Note is followed where required.


  • Create and deploy a contract

    • Make a .sol in /sawtooth-seth/contracts/.

    It goes unsaid write logic of transactions in the sol file

    • Get bytecode by executing $ solc --bin contract.sol.

    If solc is unintalled install it using official ethereum docs

    • Copy the hexadecimal bytecode to someplace.
    • Deploy the contract as followed
      • In a free terminal (Not in listning mode) execute curl -d '{"jsonrpc": "2.0", "method": "eth_sendTransaction", "id": 2, "params": [{ "from": "0x{address}", "data": "0x{contract}" }]}' -H "Content-Type: application/json" localhost:3030
        • The address is the address of account that was unlocked before, contract is the bytecode you just copied.

Note: If you're unable to deploy or getting account not found/ No resource error

  • Re-read the above notes and find which step you missed
  • Ensure the address is read by ethAccounts like tested above.
  • Make sure you imported and created the account like said above.
  • honestly, it's re-testing every step that helped me.

  • Verify the contract
    • If the contract had passed, a JSON object would be returned with Transactionsid
    • Run $ curl -d '{"jsonrpc": "2.0", "method": "eth_getTransactionReceipt", "id": 3, "params": ["0x{Transactionsid}"] }' -H "Content-Type: application/json" localhost:3030
    • If you get response then you've deployed it successfully.

For more JSONRPC messages:

Disclamer:

  • All the information above is collected from https://chat.hyperledger.org/channel/sawtooth-seth and github issues, pull requests.
  • I have not created any of the above solutions provided.
  • Purpose of this page was to smooth the process of a new dev into the seth environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment