In Ethereum, we provide instructions to abigen
our smart contract Go language files, and many tutorials on the web are based on this directive to generate contract go files for operation. Reference:
Github A source code implementation
Use the go language to interact with Ethereum smart contracts
But these articles are old .... There are problems that make you crash.
abigen
Inside is actually called solc
to the contract file to compile the corresponding language version of the code file, according to the tutorial normally only need such a line of instructions can be done
abigen --sol yourContract.sol --pkg main --out yourContract.go
However, the current version executes the above instruction directly on the contract file and returns such a line error
Failed to build Solidity contract: exit status 7
Unable to locate the actual problem point, the Internet did not search for the corresponding problem discussion
And finally, through my own discovery, we can do this.
First pass solc
The new instructions solcjs
(direct npm install -g solc
Download instructions, solc
instructions required npm install -g solc-cli
) to generate the corresponding bin
abi
contract file
// 生成合约 abi 文件solcjs yourContract.sol -o filedir --abi// 生成合约 bin 文件solcjs yourContract.sol -o filedir --bin
Finally use Ethereum to abigen
generate the corresponding go file
abigen --abi filedir/yourContract.abi --bin filedir/yourContract.bin --pkg main --out yourContract.go
Check discovery is similar to the content of the tutorial generated go file, and further interactive use continues to be studied