https://examples.near.org/rust-status-message
You can deploy your smart contract using:
near deploy --wasmFile res/status_message.wasm --accountId YOUR_ACCOUNT_NAME
And we are calling the contract function set_status using:
near call YOUR_ACCOUNT_NAME set_status '{"message": "aloha friend"}' --accountId YOUR_ACCOUNT_NAME
The function is here:
#[near_bindgen]
impl StatusMessage {
pub fn set_status(&mut self, message: String) {
env::log(b"A");
let account_id = env::signer_account_id();
self.records.insert(&account_id, &message);
}
pub fn get_status(&self, account_id: String) -> Option<String> {
env::log(b"A");
return self.records.get(&account_id);
}
}
How does near protocol distinguish between contract?
What if some other contracts have set_status function, which contract function it will call. Also what if I redeploy the contract and run the function. Which contract function will it call?
Here's what you need to know that will hopefully clear this up:
your-account.testnet
could be your main developer account on TestNetcontract-v1.your-account.testnet
could be v1 of a contract you wroteyour-token.your-account.testnet
could be a fungible token that you controlWhen working with our examples, the deployment process uses the near dev-deploy
command which does 4 things in 2 steps (see attached image from NEAR Explorer)
step 1 (batch transaction)
your-account
) FullAccess
key to that account step 2
path/to.wasm
) to the new account (your-account
) The deploy command you included above
near deploy --wasmFile path/to.wasm --accountId YOUR_ACCOUNT_NAME
only does the last step, 2.1.
For the first 3 things in step 1 (1.1 - 1.3) you will need this:
near create_account a-contract-on.your-account.testnet --master-account your-account.testnet --helper-url https://helper.testnet.near.org
where your-account.testnet
was created beforehand using NEAR Wallet
You can see these links for more details: