LoginSignup
5
5

More than 5 years have passed since last update.

Truffle でコントラクトの ABI を取得

Last updated at Posted at 2018-05-05

Truffle でビルド済みのコントラクトの ABI を取得する方法を紹介します。

一番簡単なのは、./build/contracts ディレクトリにビルド済みのコントラクト ABI や bytecode が記録されている JSON ファイルがあるので、そこから取得する方法です。

たとえば、ExampleSmartContract というクラスをコンパイルすると、./build/contracts/ExampleSmartContract.json というファイルができているので、そのなかの abi の値をみます。

サンプルコード

  • JavaScript (Node.js) によるサンプルコードです。
  • ExampleSmartContract というクラスをコンパイルした場合のサンプルです。
const fs = require('fs');
const contract = JSON.parse(fs.readFileSync('./build/contracts/ExampleSmartContract.json', 'utf8'));
console.log(JSON.stringify(contract.abi));

参考

Note

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5