Truffle TxTypeLegacyTransaction 에러

truffle을 이용해서 개발을 진행하려고 하는데

공식 문서를 보고
진행하는데 자꾸 에러메시지가 나옵니다.

어떤 contract를 migrate 하더라도


   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xa6db1c3510716ff87d3778fa6f9992bf65cff3fab8c39ee2ed2aef4efd5773c0

Error: Given value "TxTypeLegacyTransaction" is not a valid hex string.
    at Object.hexToNumber (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-utils/lib/utils.js:205:1)
    at Method.outputTransactionFormatter (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/lib/formatters.js:214:1)
    at Method.web3.eth.getTransaction.method.outputFormatter (/usr/local/lib/node_modules/truffle/build/webpack:/packages/interface-adapter/dist/shim/overloads/ethereum.js:52:1)
    at Method.formatOutput (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-core-method/lib/index.js:146:1)
    at sendTxCallback (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-core-method/lib/index.js:522:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-core-requestmanager/lib/index.js:307:1
    at finished (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/web3-provider-engine/index.js:152:9)
    at apply (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/async/internal/once.js:12:16)
    at callback (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/async/internal/eachOfLimit.js:61:25)
    at replenish (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/async/internal/eachOfLimit.js:71:9)
    at t.default (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/async/eachLimit.js:43:3)
    at fn (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/async/internal/doLimit.js:9:16)
    at eachSeries (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/web3-provider-engine/index.js:127:5)
    at end (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/src/subproviders/provider.js:19:5)
    at t.callback [as onreadystatechange] (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/caver-js/packages/caver-core-requestmanager/caver-providers-http/src/index.js:119:13)
    at t.call [as dispatchEvent] (/Users/유저이름/Desktop/truffle/node_modules/truffle-hdwallet-provider-klaytn/dist/webpack:/truffle-hdwallet-provider/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
- Blocks: 0            Seconds: 0

라는 에러 메시지가 나옵니다.

module.exports = {
  // Uncommenting the defaults below 
  // provides for an easier quick-start with Ganache.
  // You can also follow this format for other networks;
  // see <http://truffleframework.com/docs/advanced/configuration>
  // for more details on how to specify configuration options!
  //
  //networks: {
  //  development: {
  //    host: "127.0.0.1",
  //    port: 7545,
  //    network_id: "*"
  //  },
  //  test: {
  //    host: "127.0.0.1",
  //    port: 7545,
  //    network_id: "*"
  //  }
  //},
  //
  // Truffle DB is currently disabled by default; to enable it, change enabled:
  // false to enabled: true. The default storage location can also be
  // overridden by specifying the adapter settings, as shown in the commented code below.
  //
  // NOTE: It is not possible to migrate your contracts to truffle DB and you should
  // make a backup of your artifacts to a safe location before enabling this feature.
  //
  // After you backed up your artifacts you can utilize db by running migrate as follows: 
  // $ truffle migrate --reset --compile-all
  //
  // db: {
    // enabled: false,
    // host: "127.0.0.1",
    // adapter: {
    //   name: "sqlite",
    //   settings: {
    //     directory: ".db"
    //   }
    // }
  // }
};
const HDWalletProvider = require("truffle-hdwallet-provider-klaytn");

const privateKey = "개인키";

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8551,
      network_id: "*", // Match any network id
    },
    klaytn: {
      provider: () => {
        const pks = JSON.parse(
          fs.readFileSync(path.resolve(__dirname) + "/privateKeys.js")
        );

        return new HDWalletProvider(
          pks,
          "http://localhost:8551",
          0,
          pks.length
        );
      },
      network_id: "1001", //Klaytn baobab testnet's network id
      gas: "8500000",
      gasPrice: null,
    },
    kasBaobab: {
      provider: () => {
        const option = {
          headers: [
            {
              name: "Authorization",
              value:
                "Basic " +
                Buffer.from(accessKeyId + ":" + secretAccessKey).toString(
                  "base64"
                ),
            },
            { name: "x-chain-id", value: "1001" },
          ],
          keepAlive: false,
        };
        return new HDWalletProvider(
          privateKey,
          new Caver.providers.HttpProvider(
            "https://node-api.klaytnapi.com/v1/klaytn",
            option
          )
        );
      },
      network_id: "1001", //Klaytn baobab testnet's network id
      gas: "8500000",
      gasPrice: "25000000000",
    },
    kasCypress: {
      provider: () => {
        const option = {
          headers: [
            {
              name: "Authorization",
              value:
                "Basic " +
                Buffer.from(accessKeyId + ":" + secretAccessKey).toString(
                  "base64"
                ),
            },
            { name: "x-chain-id", value: "8217" },
          ],
          keepAlive: false,
        };
        return new HDWalletProvider(
          cypressPrivateKey,
          new Caver.providers.HttpProvider(
            "https://node-api.klaytnapi.com/v1/klaytn",
            option
          )
        );
      },
      network_id: "8217", //Klaytn baobab testnet's network id
      gas: "8500000",
      gasPrice: "25000000000",
    },
    baobab: {
      provider: () => {
        return new HDWalletProvider(privateKey, "https://kaikas.baobab.klaytn.net:8651/");
      },
      network_id: "1001", //Klaytn baobab testnet's network id
      gas: "8500000",
      gasPrice: null,
    },
    cypress: {
      provider: () => {
        return new HDWalletProvider(privateKey, "http://your.cypress.en:8551");
      },
      network_id: "8217", //Klaytn mainnet's network id
      gas: "8500000",
      gasPrice: null,
    },
  },
  compilers: {
    solc: {
       version: "0.5.6",    // Fetch exact version from solc-bin (default: truffle's version)
       //docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
       settings: {          // See the solidity docs for advice about optimization and evmVersion
        optimizer: {
          enabled: false,
          runs: 200
        },
        evmVersion: "constantinople"
       }
    }
  }
};

truffle-config.js 파일은 위와 같으며

 compilers: {
    solc: {
       version: "0.5.6",    // Fetch exact version from solc-bin (default: truffle's version)
       //docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
       settings: {          // See the solidity docs for advice about optimization and evmVersion
        optimizer: {
          enabled: false,
          runs: 200
        },
        evmVersion: "constantinople"
       }
    }
  }

 HDWalletProvider(privateKey, "https://kaikas.baobab.klaytn.net:8651/");

위의 내용만 baobab 설정값 변경 및 추가하여 공식문서 예제와 동일합니다.
node.js version 은 v10.24.1 입니다.

1 Like

안녕하세요, 클레이튼 포럼에 질문을 올려주셔서 감사드립니다.

사용하신 truffle 버전도 알 수 있을까요?

npm install -g를 통해 설치하셨으면 아래 커맨드로 확인하실 수 있습니다.

$ truffle version

혹은 내부 패키지로 설치하셨으면 아래 명령어 실행 부탁드립니다.

$ ./node_modules/.bin/truffle version
1 Like

버전을 여러가지 바꾸고 설정하여 어찌저찌 해당 내용을 수정하였는데 새로운 에러가 발생하였습니다…

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'testnet'
> Network id:      1001
> Block gas limit: 0 (0x0)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xc29d0b184d6cbc832d8fd8fe291c3181d5173780d930580732c90074c671b056
   > Blocks: 0            Seconds: 0
   > contract address:    0xf459c56FF9140A85aE43EE38b890f55AD9D41E3e
   > block number:        68752087
   > block timestamp:     1630316948
   > account:             0x92799E989a144d110E1f24aB20cdCef1dcE03493
   > balance:             4.5222799
   > gas used:            1706056 (0x1a0848)
   > gas price:           25 gwei
   > value sent:          0 ETH
   > total cost:          0.0426514 ETH


   ⠋ Saving migration to chain.
TypeError: migrations.setCompleted is not a function
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:103:1)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:212:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.runAll (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:263:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:228:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:140:1)

제 버전은

Truffle v5.3.4 (core: 5.3.4)
Solidity - 0.5.0 (solc-js)
Node v14.15.5
Web3.js v1.3.5

이렇게 쓰고있습니다…

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/ownership/Ownable.sol";


contract Migrations is ERC20Detailed,ERC20, Ownable{
    constructor() ERC20Detailed('testcoin','tc',18) public {
        _mint(msg.sender, 10000*10**18);
    }
}

ERC20으로 토큰을 간단히 만들어만 보려고 하는데 자꾸 에러만 잡고 있으니까 지치네요 ㅠㅠㅠ

아마 Truffle version이 호환되지 않는 것 같습니다.

공식 문서상에서는 v5.0.26까지 지원한다고 적혀있고, 제가 개인적으로 테스트한 버전은 5.1.23입니다. 이런 버전들로 사용해 보시길 부탁드립니다.

추가적으로 GitHub - klaytn/klaytn-contracts 이 깃헙 코드도 참고 부탁드립니다.

클레이튼에서 트러플로 빌드하는 기본적인 환경이 설정되어 있습니다.

감사합니다.

1 Like