Human-Readable ABI 方式调用solidity 合约,go版。
上周在群聊吹牛,吹吹我写的golang 调用solana合约的东西。有人说他要学习go调用solidity的方法。我看了看我在登链的无abi调用合约的方法,写的python的,ethers的,solidity的,就是没写golang的,确实可以写写。
那个群里人都说用chatgpt都会用abigen的方式生成go包的方式调用合约方法。 所以我讲种不需要使用abigen生成go包的方法调用合约。
我还是喜欢使用我的晓道fork版,https://github.com/daog1/ethgo fork自,umbracle/ethgo 好处我不讲,自己读代码。
合约调用最早都是需要abi文件生成的方式,后面还是有了更简单方式,最早我是ethers里面看到叫
A Human-Readable ABI
ethers是这么写的:
// A Human-Readable ABI; for interacting with the contract, we
// must include any fragment we wish to use
const abi = [
// Read-Only Functions
"function balanceOf(address owner) view returns (uint256)",
"function decimals() view returns (uint8)",
"function symbol() view returns (string)",
// Authenticated Functions
"function transfer(address to, uint amount) returns (bool)",
// Events
"event Transfer(address indexed from, address indexed to, uint amount)"
];
// This can be an address or an ENS name
const address = "0x70ff5c5B1Ad0533eAA5489e0D5Ea01485d530674";
// Read-Only; By connecting to a Provider, allows:
// - Any constant function
// - Querying Filters
// - Populating Unsigned...
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!