From 4712997df5d339be33edcceedceed18f42e335af Mon Sep 17 00:00:00 2001 From: Nico Serrano <38594836+NicoSerranoP@users.noreply.github.com> Date: Wed, 1 Jun 2022 15:29:45 -0500 Subject: [PATCH 1/4] Update direct binding from sol to go using abigen The new abigen version does not have the --solc file to directly bind a Solidity contract to a Go package. This was caused because the solc compiler in ```go-ethereum``` needed to be continuously synchronized with the original solc compiler in order to offer the full features and security of latest versions. The team decided to remove the direct biding functionality from Solidity to Go but the documentation still has it (therefore confusing newcomers with outdated instructions). --- docs/_dapp/native-bindings.md | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/docs/_dapp/native-bindings.md b/docs/_dapp/native-bindings.md index c906d1c589..5ad617deda 100644 --- a/docs/_dapp/native-bindings.md +++ b/docs/_dapp/native-bindings.md @@ -332,30 +332,17 @@ Pending name: Contracts in Go!!! ## Bind Solidity directly -If you've followed the tutorial along until this point you've probably realized that -every contract modification needs to be recompiled, the produced ABIs and bytecodes -(especially if you need multiple contracts) individually saved to files and then the -binding executed for them. This can become a quite bothersome after the Nth iteration, -so the `abigen` command supports binding from Solidity source files directly (`--sol`), -which first compiles the source code (via `--solc`, defaulting to `solc`) into it's -constituent components and binds using that. - -Binding the official Token contract [`token.sol`](https://gist.github.com/karalabe/08f4b780e01c8452d989) -would then entail to running: - +In the past, abigen allowed you to compile and bind a Solidity source file directly to a Go package. +This feature has been discontinued from [v1.10.18](https://github.com/ethereum/go-ethereum/releases/tag/v1.10.18) +onwards due to maintenance synchronization challenges with the compiler in ```go-ethereum```. +Now, to bind a Solidity source file into a go package you will have to compile it first using +any of your prefered compilers (e.g. [solc](https://docs.soliditylang.org/en/v0.8.14/installing-solidity.html) +or [Remix](https://remix.ethereum.org/)) and bind it later. Binding the official Token contract [`token.sol`](https://gist.github.com/karalabe/08f4b780e01c8452d989) would then entail to running: ``` -$ abigen --sol token.sol --pkg main --out token.go +$ solc --abi --bin token.sol -o tokenDirectory +$ abigen --abi tokenDirectory/token.abi --bin tokenDirectory/token.bin --pkg main --type token --out token.go ``` -*Note: Building from Solidity (`--sol`) is mutually exclusive with individually setting -the bind components (`--abi`, `--bin` and `--type`), as all of them are extracted from -the Solidity code and produced build results directly.* - -Building a contract directly from Solidity has the nice side effect that all contracts -contained within a Solidity source file are built and bound, so if your file contains many -contract sources, each and every one of them will be available from Go code. The sample -Token solidity file results in [`token.go`](https://gist.github.com/karalabe/c22aab73194ba7da834ab5b379621031). - ### Project integration (i.e. `go generate`) The `abigen` command was made in such a way as to play beautifully together with existing From ff3f7e76de2305884565c318f6e9ee190fb58ca9 Mon Sep 17 00:00:00 2001 From: Nico Serrano <38594836+NicoSerranoP@users.noreply.github.com> Date: Thu, 2 Jun 2022 10:09:38 -0500 Subject: [PATCH 2/4] Add another mode supported in abigen Adding the new commands requested [here](https://github.com/ethereum/go-ethereum/pull/25008#discussion_r887431130) --- docs/_dapp/native-bindings.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/_dapp/native-bindings.md b/docs/_dapp/native-bindings.md index 5ad617deda..f525051388 100644 --- a/docs/_dapp/native-bindings.md +++ b/docs/_dapp/native-bindings.md @@ -343,6 +343,14 @@ $ solc --abi --bin token.sol -o tokenDirectory $ abigen --abi tokenDirectory/token.abi --bin tokenDirectory/token.bin --pkg main --type token --out token.go ``` +You can use the ```solc``` compiler to get a single ```.json``` file containing ABI and bytecode, and then use +it as input to ```abigen``` to generate the Go package in a shorter command: +``` +$ solc token.sol --combined-json abi,bin -o . +$ abigen --combined-json combined.json --pkg main --type token --out token.go +``` + + ### Project integration (i.e. `go generate`) The `abigen` command was made in such a way as to play beautifully together with existing From 2388d1a4762be22426251aacdbaf1f15192d3fcb Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 23 Jun 2022 11:22:49 +0800 Subject: [PATCH 3/4] Update native-bindings.md --- docs/_dapp/native-bindings.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/_dapp/native-bindings.md b/docs/_dapp/native-bindings.md index f525051388..29759c51fe 100644 --- a/docs/_dapp/native-bindings.md +++ b/docs/_dapp/native-bindings.md @@ -13,7 +13,7 @@ the direction of the Mist browser, through which users can interact with the blo Although this was a solid plan for mainstream adoption and does cover quite a lot of use cases that people come up with (mostly where people manually interact with the blockchain), -it eludes the server side (backend, fully automated, devops) use cases where JavaScript is +it excludes the server side (backend, fully automated, devops) use cases where JavaScript is usually not the language of choice given its dynamic nature. This page introduces the concept of server side native Dapps: Go language bindings to any @@ -336,7 +336,7 @@ In the past, abigen allowed you to compile and bind a Solidity source file direc This feature has been discontinued from [v1.10.18](https://github.com/ethereum/go-ethereum/releases/tag/v1.10.18) onwards due to maintenance synchronization challenges with the compiler in ```go-ethereum```. Now, to bind a Solidity source file into a go package you will have to compile it first using -any of your prefered compilers (e.g. [solc](https://docs.soliditylang.org/en/v0.8.14/installing-solidity.html) +any of your prefered approaches (e.g. [solc](https://docs.soliditylang.org/en/v0.8.14/installing-solidity.html) or [Remix](https://remix.ethereum.org/)) and bind it later. Binding the official Token contract [`token.sol`](https://gist.github.com/karalabe/08f4b780e01c8452d989) would then entail to running: ``` $ solc --abi --bin token.sol -o tokenDirectory @@ -350,6 +350,10 @@ $ solc token.sol --combined-json abi,bin -o . $ abigen --combined-json combined.json --pkg main --type token --out token.go ``` +Even you can combine these two steps together as a pipeline +``` +solc token.sol --combined-json abi,bin | abigen --pkg contract --out contract.go --combined-json - +``` ### Project integration (i.e. `go generate`) From 3246b8d44f85456864680c74d5d787423f058ba6 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 23 Jun 2022 11:24:33 +0800 Subject: [PATCH 4/4] Update native-bindings.md --- docs/_dapp/native-bindings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_dapp/native-bindings.md b/docs/_dapp/native-bindings.md index 29759c51fe..e7e1457fe7 100644 --- a/docs/_dapp/native-bindings.md +++ b/docs/_dapp/native-bindings.md @@ -352,7 +352,7 @@ $ abigen --combined-json combined.json --pkg main --type token --out token.go Even you can combine these two steps together as a pipeline ``` -solc token.sol --combined-json abi,bin | abigen --pkg contract --out contract.go --combined-json - +solc token.sol --combined-json abi,bin | abigen --pkg main --type token --out token.go --combined-json - ``` ### Project integration (i.e. `go generate`)