在本地以太坊私链上,使用go调用智能合约,获取事件日志

1、关于开发环境搭建配置等可参考之前的文章
2、部署合约代码erc20.js

const hre = require("hardhat");
async function main() {
  const CONTRACT = await hre.ethers.getContractFactory("ERC20");

  const contract = await CONTRACT.deploy();
  await contract.init("ERC20Name","ERC20Symbol");
  console.log("name:",contract.name(),"symbol:",contract.symbol());
  await contract.deployed();

  console.log(`contract deployed to ${contract.address}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

3、启动并上链

#切换到智能合约项目位置
npx hardhat node
#新开一个窗口,确保localhost已经在hardhat.config.js中配置了,可查看第一步链接对照
npx hardhat run scripts/erc.js --network localhost


4、新建一个文件夹,存放go项目,完成mod初始化等

完整go项目文件目录


5、拷贝智能合约compile产生的ABI,在新文件夹中新建一个erc20.json文件

 

 

6、安装abigen

go get github.com/ethereum/go-ethereum

#切换路径 cd $GOPATH/pkg/mod/github.com/ethereum/go-ethereum@v1
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值