Web3-Blue: Smart Contracts Pattern

This pattern implements a service for interaction with Solidity Smart Contracts, enabling the user to read and write to a deployed contract instance. Additionally, the pattern includes a deployment playground for configuring and deploying custom smart contracts.

image

Prerequisites 📘

The pattern requires the web3-blue nodes installed in the Node-RED environment.

Deployment Playground 🎮

image Use the deployment playground to create a custom contract deployment.

Ganache RPC 🔩

The playground faciliatates a start, stop and list injector for the creation of local Ganache instances. After you start your Ganache server, click the accounts injector to view all the available accounts in that RPC server.

Deploying Contracts 📜

The deploy injector deploys a SimpleStorage smart contract so that you can experiment with the flow. Develop and compile your Smart Contract in an IDE like Remix or by using a framework like Hardhat and Truffle. Get the compiled ABI and Bytecode of the contract and go ahead and customize the Deployment Configuration node. Configure the Deployment Configuration change node in order to define the ABI, Bytecode and Args (constructor parameters) of the smart contract to be deployed.

[{"id":"e9bba491d5a7885f","type":"tab","label":"SmartContracs Pattern","disabled":false,"info":"","env":[]},{"id":"042b103cb566d65c","type":"group","z":"e9bba491d5a7885f","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["04aebaacedaccb82","1b8ef0af1f1024f2","1505373354dfe981","6ca7e17e53f9b85b","29b57ad9eca4d11e","27d84867d3f0b3a0","4973eb32240f788c","fce3e433b9c38f6f","5088fabb8af13f6e","a99f9da162db7aee","b382db1b4b77b8d3","e4b214bc5ed09ef3","3fc4b98ea7641c8b","e042b0d9b6934979","af9298fc9561f962"],"x":74,"y":559,"w":852,"h":242},{"id":"04aebaacedaccb82","type":"inject","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"stop","props":[{"p":"stop","v":"true","vt":"bool"},{"p":"instance","v":"candied_strawberry_drizzle","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":640,"wires":[["4973eb32240f788c"]]},{"id":"1b8ef0af1f1024f2","type":"inject","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"start","props":[{"p":"start","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":600,"wires":[["4973eb32240f788c"]]},{"id":"1505373354dfe981","type":"debug","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":600,"wires":[]},{"id":"e2d481c5250ebc50","type":"http in","z":"e9bba491d5a7885f","name":"","url":"/call","method":"post","upload":false,"swaggerDoc":"","x":140,"y":180,"wires":[["f4041e7e378986bf"]]},{"id":"aa64b53bc0478a77","type":"http in","z":"e9bba491d5a7885f","name":"","url":"/send","method":"post","upload":false,"swaggerDoc":"","x":150,"y":260,"wires":[["f4041e7e378986bf"]]},{"id":"6ca7e17e53f9b85b","type":"inject","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"deploy","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":720,"wires":[["fce3e433b9c38f6f"]]},{"id":"29b57ad9eca4d11e","type":"change","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"Deployment Configuration","rules":[{"t":"set","p":"account","pt":"msg","to":"payload[0]","tot":"msg"},{"t":"set","p":"bytecode","pt":"msg","to":"60806040523480156200001157600080fd5b5060405162000bf238038062000bf28339818101604052810190620000379190620001e3565b80600090816200004891906200047f565b505062000566565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620000b9826200006e565b810181811067ffffffffffffffff82111715620000db57620000da6200007f565b5b80604052505050565b6000620000f062000050565b9050620000fe8282620000ae565b919050565b600067ffffffffffffffff8211156200012157620001206200007f565b5b6200012c826200006e565b9050602081019050919050565b60005b83811015620001595780820151818401526020810190506200013c565b60008484015250505050565b60006200017c620001768462000103565b620000e4565b9050828152602081018484840111156200019b576200019a62000069565b5b620001a884828562000139565b509392505050565b600082601f830112620001c857620001c762000064565b5b8151620001da84826020860162000165565b91505092915050565b600060208284031215620001fc57620001fb6200005a565b5b600082015167ffffffffffffffff8111156200021d576200021c6200005f565b5b6200022b84828501620001b0565b91505092915050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200028757607f821691505b6020821081036200029d576200029c6200023f565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b600060088302620003077fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82620002c8565b620003138683620002c8565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b6000620003606200035a62000354846200032b565b62000335565b6200032b565b9050919050565b6000819050919050565b6200037c836200033f565b620003946200038b8262000367565b848454620002d5565b825550505050565b600090565b620003ab6200039c565b620003b881848462000371565b505050565b5b81811015620003e057620003d4600082620003a1565b600181019050620003be565b5050565b601f8211156200042f57620003f981620002a3565b6200040484620002b8565b8101602085101562000414578190505b6200042c6200042385620002b8565b830182620003bd565b50505b505050565b600082821c905092915050565b6000620004546000198460080262000434565b1980831691505092915050565b60006200046f838362000441565b9150826002028217905092915050565b6200048a8262000234565b67ffffffffffffffff811115620004a657620004a56200007f565b5b620004b282546200026e565b620004bf828285620003e4565b600060209050601f831160018114620004f75760008415620004e2578287015190505b620004ee858262000461565b8655506200055e565b601f1984166200050786620002a3565b60005b8281101562000531578489015182556001820191506020850194506020810190506200050a565b868310156200055157848901516200054d601f89168262000441565b8355505b6001600288020188555050505b505050505050565b61067c80620005766000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c14610057575b600080fd5b61005560048036038101906100509190610274565b610075565b005b61005f610088565b60405161006c919061033c565b60405180910390f35b80600090816100849190610574565b5050565b6060600080546100979061038d565b80601f01602080910402602001604051908101604052809291908181526020018280546100c39061038d565b80156101105780601f106100e557610100808354040283529160200191610110565b820191906000526020600020905b8154815290600101906020018083116100f357829003601f168201915b5050505050905090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61018182610138565b810181811067ffffffffffffffff821117156101a05761019f610149565b5b80604052505050565b60006101b361011a565b90506101bf8282610178565b919050565b600067ffffffffffffffff8211156101df576101de610149565b5b6101e882610138565b9050602081019050919050565b82818337600083830152505050565b6000610217610212846101c4565b6101a9565b90508281526020810184848401111561023357610232610133565b5b61023e8482856101f5565b509392505050565b600082601f83011261025b5761025a61012e565b5b813561026b848260208601610204565b91505092915050565b60006020828403121561028a57610289610124565b5b600082013567ffffffffffffffff8111156102a8576102a7610129565b5b6102b484828501610246565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156102f75780820151818401526020810190506102dc565b60008484015250505050565b600061030e826102bd565b61031881856102c8565b93506103288185602086016102d9565b61033181610138565b840191505092915050565b600060208201905081810360008301526103568184610303565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806103a557607f821691505b6020821081036103b8576103b761035e565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026104207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826103e3565b61042a86836103e3565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b600061047161046c61046784610442565b61044c565b610442565b9050919050565b6000819050919050565b61048b83610456565b61049f61049782610478565b8484546103f0565b825550505050565b600090565b6104b46104a7565b6104bf818484610482565b505050565b5b818110156104e3576104d86000826104ac565b6001810190506104c5565b5050565b601f821115610528576104f9816103be565b610502846103d3565b81016020851015610511578190505b61052561051d856103d3565b8301826104c4565b50505b505050565b600082821c905092915050565b600061054b6000198460080261052d565b1980831691505092915050565b6000610564838361053a565b9150826002028217905092915050565b61057d826102bd565b67ffffffffffffffff81111561059657610595610149565b5b6105a0825461038d565b6105ab8282856104e7565b600060209050601f8311600181146105de57600084156105cc578287015190505b6105d68582610558565b86555061063e565b601f1984166105ec866103be565b60005b82811015610614578489015182556001820191506020850194506020810190506105ef565b86831015610631578489015161062d601f89168261053a565b8355505b6001600288020188555050505b50505050505056fea264697066735822122075ae2d522cc78bbc654df02ab06c3759c71796f38da66f69487b666fca10da6964736f6c63430008120033","tot":"str"},{"t":"set","p":"abi","pt":"msg","to":"[ \t\t{ \t\t\t\"inputs\": [ \t\t\t\t{ \t\t\t\t\t\"internalType\": \"string\", \t\t\t\t\t\"name\": \"initialStore\", \t\t\t\t\t\"type\": \"string\" \t\t\t\t} \t\t\t], \t\t\t\"stateMutability\": \"nonpayable\", \t\t\t\"type\": \"constructor\" \t\t}, \t\t{ \t\t\t\"inputs\": [], \t\t\t\"name\": \"get\", \t\t\t\"outputs\": [ \t\t\t\t{ \t\t\t\t\t\"internalType\": \"string\", \t\t\t\t\t\"name\": \"\", \t\t\t\t\t\"type\": \"string\" \t\t\t\t} \t\t\t], \t\t\t\"stateMutability\": \"view\", \t\t\t\"type\": \"function\" \t\t}, \t\t{ \t\t\t\"inputs\": [ \t\t\t\t{ \t\t\t\t\t\"internalType\": \"string\", \t\t\t\t\t\"name\": \"newStore\", \t\t\t\t\t\"type\": \"string\" \t\t\t\t} \t\t\t], \t\t\t\"name\": \"set\", \t\t\t\"outputs\": [], \t\t\t\"stateMutability\": \"nonpayable\", \t\t\t\"type\": \"function\" \t\t} \t]","tot":"json"},{"t":"set","p":"args","pt":"msg","to":"[\"Hello Contract\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":680,"wires":[["5088fabb8af13f6e"]]},{"id":"27d84867d3f0b3a0","type":"comment","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"ν Configure Me! ν","info":"# Deployment Configuration\n\n## RPC\nIn the change node below locate **msg.rpc**, this is where you configure the RPC url.\n## Account\nIn the change node below locate **msg.account**, this is where you configure the web3 account.\n## Contract\nIn the change node below locate **msg.bytecode**,**msg.abi** and **msg.args**.\nThese parameters allow you to configure what Smart Contract to deploy.\nYou can get the bytecode and abi of the contract by compiling in Remix or using Truffle.\nThe **msg.args** parameters requires the contract constructor parameters.\n\n","x":440,"y":640,"wires":[]},{"id":"b137d1cf83962284","type":"comment","z":"e9bba491d5a7885f","name":"Deployment Playground","info":"","x":180,"y":540,"wires":[]},{"id":"f4041e7e378986bf","type":"change","z":"e9bba491d5a7885f","name":"Contract Options","rules":[{"t":"set","p":"function","pt":"msg","to":"req.url","tot":"msg"},{"t":"move","p":"payload.account","pt":"msg","to":"account","tot":"msg"},{"t":"move","p":"payload.function","pt":"msg","to":"contractFunction","tot":"msg"},{"t":"move","p":"payload.args","pt":"msg","to":"contractArgs","tot":"msg"},{"t":"move","p":"payload.gasLimit","pt":"msg","to":"gasLimit","tot":"msg"},{"t":"set","p":"contractAddress","pt":"msg","to":"address","tot":"flow"},{"t":"set","p":"abi","pt":"msg","to":"abi","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":220,"wires":[["35f03607dc5ba23c"]]},{"id":"35f03607dc5ba23c","type":"switch","z":"e9bba491d5a7885f","name":"Function","property":"function","propertyType":"msg","rules":[{"t":"eq","v":"/call","vt":"str"},{"t":"eq","v":"/send","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":520,"y":220,"wires":[["97ef19d8161cbafd"],["2a91af11f0a6fa2c"]]},{"id":"d5beb8690df00e3c","type":"http response","z":"e9bba491d5a7885f","name":"","statusCode":"","headers":{},"x":1030,"y":200,"wires":[]},{"id":"537a84e32f261a32","type":"inject","z":"e9bba491d5a7885f","name":"","props":[{"p":"payload.account","v":"0x6176c6122f7F561F95A050920589e8b40e19C21f","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"function\":\"get\",\"args\":[]}","payloadType":"json","x":150,"y":380,"wires":[["1ab18298ca4fb096"]]},{"id":"1ab18298ca4fb096","type":"http request","z":"e9bba491d5a7885f","name":"Request Call","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/call","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":390,"y":380,"wires":[["ae89f277b9811417"]]},{"id":"dcf57a469fa0536d","type":"http request","z":"e9bba491d5a7885f","name":"Request Send","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/send","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":380,"y":480,"wires":[["ae89f277b9811417"]]},{"id":"35705ef87b9ad9b3","type":"comment","z":"e9bba491d5a7885f","name":"TEST: Contract Call","info":"","x":170,"y":340,"wires":[]},{"id":"1ed971df1b934df3","type":"comment","z":"e9bba491d5a7885f","name":"TEST: Contract Send","info":"","x":180,"y":440,"wires":[]},{"id":"ae89f277b9811417","type":"debug","z":"e9bba491d5a7885f","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":440,"wires":[]},{"id":"a99f9da162db7aee","type":"inject","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"accounts","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":760,"wires":[["b382db1b4b77b8d3"]]},{"id":"e4b214bc5ed09ef3","type":"debug","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":760,"wires":[]},{"id":"fef04333f80ca183","type":"inject","z":"e9bba491d5a7885f","name":"","props":[{"p":"payload.account","v":"0x6176c6122f7F561F95A050920589e8b40e19C21f","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"function\":\"set\",\"args\":[\"Hello Example\"]}","payloadType":"json","x":150,"y":480,"wires":[["dcf57a469fa0536d"]]},{"id":"792c651f2e91b104","type":"change","z":"e9bba491d5a7885f","name":"TX","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.transactionHash","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":240,"wires":[["d5beb8690df00e3c"]]},{"id":"4973eb32240f788c","type":"rpc","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"Ganache RPC Server","function":"Ganache Server","ip":"127.0.0.1","port":"8085","rpc":"","account":"","block":"","x":440,"y":600,"wires":[["af9298fc9561f962"]]},{"id":"fce3e433b9c38f6f","type":"rpc","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"","function":"Get Accounts","ip":"127.0.0.1","port":"8085","rpc":"http://localhost:8085","account":"","block":"","x":330,"y":720,"wires":[["29b57ad9eca4d11e"]]},{"id":"b382db1b4b77b8d3","type":"rpc","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"","function":"Get Accounts","ip":"127.0.0.1","port":"8085","rpc":"http://localhost:8085","account":"","block":"","x":530,"y":760,"wires":[["e4b214bc5ed09ef3"]]},{"id":"5088fabb8af13f6e","type":"contracts","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"","function":"Deploy Contract","rpc":"http://localhost:8085","abi":[],"bytecode":"","arguments":[],"account":"","password":"","contractAddress":"","contractFunction":"","contractArgs":[],"gasLimit":"","value":"","x":540,"y":720,"wires":[["3fc4b98ea7641c8b","e4b214bc5ed09ef3"]]},{"id":"97ef19d8161cbafd","type":"contracts","z":"e9bba491d5a7885f","name":"","function":"Call to Contract","rpc":"http://localhost:8085","abi":[],"bytecode":"","arguments":[],"account":"","password":"","contractAddress":"","contractFunction":"","contractArgs":[],"gasLimit":"20000000","value":"","x":720,"y":200,"wires":[["d5beb8690df00e3c"]]},{"id":"2a91af11f0a6fa2c","type":"contracts","z":"e9bba491d5a7885f","name":"","function":"Send to Contract","rpc":"http://localhost:8085","abi":[],"bytecode":"","arguments":[],"account":"","password":"","contractAddress":"","contractFunction":"","contractArgs":[],"gasLimit":"20000000","value":"","x":730,"y":240,"wires":[["792c651f2e91b104"]]},{"id":"3fc4b98ea7641c8b","type":"change","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"Contract\\n Address & ABI","rules":[{"t":"set","p":"address","pt":"flow","to":"payload.address","tot":"msg"},{"t":"set","p":"abi","pt":"flow","to":"payload.jsonInterface","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":680,"wires":[[]]},{"id":"e042b0d9b6934979","type":"inject","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"list","props":[{"p":"list","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":680,"wires":[["4973eb32240f788c"]]},{"id":"af9298fc9561f962","type":"change","z":"e9bba491d5a7885f","g":"042b103cb566d65c","name":"RPC Instance","rules":[{"t":"set","p":"instance","pt":"flow","to":"payload.start","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":600,"wires":[["1505373354dfe981"]]}]

Flow Info

Created 1 year, 8 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x5)
  • comment (x4)
  • debug (x3)
  • http in (x2)
  • http request (x2)
  • http response (x1)
  • inject (x7)
  • switch (x1)
Other

Tags

  • web3-blue
  • physics
  • patterns
  • smart-contracts
  • blockchain
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option