1

When writing contracts, the contract class in file name_a.cpp is defined as follows:

class[[eosio::contract("name_a")]] name_b : public contract {..}

In my understanding the name of the class is name_b and the contract is called name_a.

The contract is then deployed to the testnet with the following command with an account named name_c:

cleos -u https://testnet.waxsweden.org set contract name_c /path/to/contract/ name_a.wasm name_a.abi -p name_c@active

What exactly is the name of this contract which must be used for transactions?

My guess would be name_c as this is the name of the account that owns the contract. But what happens with the name specified in [[eosio::contract("name_a")]]? For what is it used?

0

My guess would be name_c as this is the name of the account that owns the contract.

Correct.

But what happens with the name specified in [[eosio::contract("name_a")]]? For what is it used?

Let's say your headers define multiple contract classes. e.g.

struct [[eosio::contract("contract.1")]] class_1 : eosio::contract
{
   using eosio::contract::contract;
   [[eosio::action]] void act1() {}
};

struct [[eosio::contract("contract.1")]] class_2 : eosio::contract
{
   using eosio::contract::contract;
   [[eosio::action]] void act2() {}
};

struct [[eosio::contract("contract.2")]] class_3 : eosio::contract
{
   using eosio::contract::contract;
   [[eosio::action]] void act3() {}
};

You could do this for multiple reasons:

  • You want to split up your code into multiple classes.
  • You include another contract's headers to make it easier to create inline actions to it.

The compiler matches the name in [[eosio::contract("name")]] against the command-line option -contract to decide which classes to build into your contract.

e.g. eosio-cpp -contract=contract.1 file.cpp includes act1 and act2 in the contract, while eosio-cpp -contract=contract.2 file.cpp includes act3 instead.

2
  • Thank you very much! When referring to a specific action of a specific contract by on-notify, would you also use the name of the account that owns the contract? In my example: [[eosio::on_notify("name_c::someAction")]] ?
    – sam
    yesterday
  • yes, it needs the actual account name yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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