Skip to content

Unable to deploy Ink smart contract to the local node. #2617

@Subway2023

Description

@Subway2023

Reference link: creating-an-ink-project, hardhat-deployment
Problem: unable to successfully deploy the contract following the documentation.
Aim: deploy the Ink contract with a Solidity-compatible ABI and invoke it for differential testing

ink smart contract project

cargo contract new flipper

Change abi = "ink" to abi = "sol" in Cargo.toml

cargo contract build

hardhat project

mkdir hardhat-example
cd hardhat-example
npm init -y

npm install --save-dev @parity/hardhat-polkadot

npx hardhat-polkadot init
npm install

hardhat.config.js(the document does not include global.WebSocket = require("ws");, which will cause an error.)

global.WebSocket = require("ws"); 

require('@nomicfoundation/hardhat-toolbox');
require('@parity/hardhat-polkadot');

module.exports = {
  // ... other config
  networks: {
    hardhat: {
      polkavm: true,
      nodeConfig: {
        nodeBinaryPath: '/mnt/sdd1/sbw/sol2rust/tool/ink-node-linux/ink-node',
        rpcPort: 8000,
        dev: true,
      },
      adapterConfig: {
        adapterBinaryPath: '/mnt/sdd1/sbw/sol2rust/tool/ink-node-linux/eth-rpc',
        dev: true,
      },
    },
    localNode: {
      polkavm: true,
      url: `http://127.0.0.1:8545`,
    },
  },
};

scripts/deploy.js

const hre = require('hardhat');
const { join } = require('path');
const { readFileSync } = require('fs');

// Import the ABI of the contract from the flipper_evm.json file.
const abi = require("/mnt/sdd1/sbw/sol2rust/test/flipper/target/ink/flipper.json").output.abi;
// console.log("abi",abi)

async function main() {
    const [deployer] = await hre.ethers.getSigners();

    // Fetch the bytecode of the contract.
    const bytecodePath = join("/mnt/sdd1/sbw/sol2rust/test/flipper/target/ink/flipper.polkavm");
    const bytecode = `0x${readFileSync(bytecodePath).toString('hex')}`;

    const flipper = new hre.ethers.ContractFactory(abi, bytecode, deployer);

    // Deploy the contract with the constructor arguments.
    const contract = await flipper.deploy(true);
    await contract.waitForDeployment();
    
    // Get the address of the deployed contract.
    const address = await contract.getAddress();
    console.log(`Contract deployed at: ${address}`);
}

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

start node

npx hardhat node

deploy

first error

npx hardhat run scripts/deploy.js --network localNode --no-compile
ProviderError: Transaction Already Imported
    at HttpProvider.request (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/hardhat/src/internal/core/providers/http.ts:116:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at HardhatEthersSigner.sendTransaction (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/@nomicfoundation/hardhat-ethers/src/signers.ts:181:18)
    at ContractFactory.deploy (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/ethers/src.ts/contract/factory.ts:111:24)
    at main (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/scripts/deploy.js:19:22)

another error

if i modify url: http://127.0.0.1:8545 to url: http://127.0.0.1:8000 in hardhat.config.js, there is another error

npx hardhat run scripts/deploy.js --network localNode --no-compile
ProviderError: Method not found
    at HttpProvider.request (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/hardhat/src/internal/core/providers/http.ts:116:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at getSigners (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/@nomicfoundation/hardhat-ethers/src/internal/helpers.ts:46:16)
    at main (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/scripts/deploy.js:10:24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions