2

how do I use the @custom:dev-run-script Nat Spec tag to run my smart contract? it keeps telling me to use it when i try to compile my smart contract in ethereum remix

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Mar 23, 2023 at 20:01

4 Answers 4

1

The default workshop includes two scripts to deploy contracts:
scripts/deploy_with_ethers.ts
scripts/deploy_with_web3.ts

If you choose the first one, you have to edit it to set the name of the contract to edit, the default value is Storage from 1_Storage.sol.

import { deploy } from './ethers-lib'

(async () => {
    try {
        const result = await deploy('Storage', [])
        console.log(`address: ${result.address}`)
    } catch (e) {
        console.log(e.message)
    }
  })()

Then you add at the beginning of your contract:

  /**
   * @title ContractName
   * @dev ContractDescription
   * @custom:dev-run-script scripts/deploy_with_ethers.ts
   */
  contract ContractName {}

Now when you hit control+shift+S, the contract is saved and published to the network configured in the "Deploy & run transaction" section (last icon from top to bottom on the left margin).

1

Just add this on top of where your contract starts.

 /**
   * @title ContractName
   * @dev ContractDescription
   * @custom:dev-run-script scripts/deploy_with_ethers.ts
   */

Adjust file path scripts/deploy_with_ethers.ts as per your setup. You will be able to use the deploy with script button in remix.

If you do not want to deploy with script you can directly deploy the contract from the sidebar and remove the scripts folder from remix.

0

To use the @custom:dev-run-script NatSpec tag, add the NatSpec tag @custom:dev-run-script to the contract followed by the absolute file path, like:

ContractName.sol:

  /**
   * @title ContractName
   * @dev ContractDescription
   * @custom:dev-run-script file_path
   */
  contract ContractName {}

Then, in your deploy script located at file_path, edit the contract name and call the methods you want to to run your contract.

file_path/deploy_script.ts:

// This script can be used to deploy the "ContractName" contract using ethers.js library.
// Please make sure to compile before running this script.
// And use Right click -> "Run" from context menu of the file to run the script. Shortcut: Ctrl+Shift+S

import { deploy } from './ethers-lib'

(async () => {
    try {
        const result = await deploy('ContractName', [<constructor args>])
        console.log(`address: ${result.address}`)
        // Call your methods and tests here
    } catch (e) {
        console.log(e.message)
    }
  })()

Then, you can run and deploy with the Ctrl+Shift+S keyboard shortcut, while Ctrl+S will only start the compiling.

Deployed contracts with callable methods and getter functions will appear in the deployed contracts section of the Deploy & Run tab.

0
/**

@title ContractName
@dev ContractDescription
@custom:dev-run-script scripts/deploy_with_ethers.ts
*/

Contract name and description are self evident, just amend as appropriate. the dev-run-script bit tells Solidity the script to run to deploy your smart contract. I just copied that bit as is and my contract runs OK.

Tried to delete one of these answers but, can't find a delete option.

1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 28, 2023 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.