Blockchain learning-golang interaction with smart contracts (i)

Source: Internet
Author: User

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.
abigenInside 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.