nearprotocol - 如何从地址调用不同的合约?

标签 nearprotocol

在 Solidity(以太坊)中,需要合约地址来调用该合约。

contract KittyInterface {
  function getKitty(uint256 _id) external view returns (
    bool isGestating,
    bool isReady,
    uint256 cooldownIndex,
    uint256 nextActionAt,
    uint256 siringWithId,
    uint256 birthTime,
    uint256 matronId,
    uint256 sireId,
    uint256 generation,
    uint256 genes
  );
}

contract ZombieFeeding is ZombieFactory {

  address ckAddress = 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d; 
  KittyInterface kittyContract = KittyInterface(ckAddress);

我可以在近协议(protocol)中做到这一点吗? 附近的示例有所不同,需要提供 wasm 文件。 https://github.com/near-examples/rust-high-level-cross-contract

pub fn deploy_status_message(&self, account_id: String, amount: u64) {
        Promise::new(account_id)
            .create_account()
            .transfer(amount as u128)
            .add_full_access_key(env::signer_account_pk())
            .deploy_contract(
                include_bytes!("../status-message-contract/status_message.wasm").to_vec(),
            );
    }

此外,我在使用高级交叉合约代码时遇到错误。 https://gateway.ipfs.io/ipfs/QmPvcjeEE5PJvaJNN2axgKVWGbWVEQCe9q4e95t9NCeGFt/

最佳答案

请看一下锁定合约示例。它使用以下内容:

        ext_whitelist::is_whitelisted(
            staking_pool_account_id.clone(),
            &self.staking_pool_whitelist_account_id,
            NO_DEPOSIT,
            gas::whitelist::IS_WHITELISTED,
        )
        .then(ext_self_owner::on_whitelist_is_whitelisted(
            staking_pool_account_id,
            &env::current_account_id(),
            NO_DEPOSIT,
            gas::owner_callbacks::ON_WHITELIST_IS_WHITELISTED,
        ))

来自 https://github.com/near/core-contracts/blob/cd221798a77d646d5f1200910d45326d11951732/lockup/src/owner.rs#L29-L40

第一个调用接口(interface)是(<arg_0>, <arg_1>, ..., <arg_n>, <ACCOUNT_ID>, <ATTACHED_DEPOSIT>, <ATTACHED_GAS>)

  • <arg_0>, <arg_1>, ..., <arg_n> - 来自下面定义的接口(interface)的参数
  • <ACCOUNT_ID> - 部署要调用的合约的账户
  • <ATTACHED_DEPOSIT> - 附加到通话的 yocto-NEAR 金额
  • <ATTACHED_GAS> - 传递给调用的 Gas 量

后来它使用 .then 将回调附加到第一个 Promise。 。回调只是另一个异步函数调用。

高级接口(interface)ext_whitelist定义如下:

#[ext_contract(ext_whitelist)]
pub trait ExtStakingPoolWhitelist {
    fn is_whitelisted(&self, staking_pool_account_id: AccountId) -> bool;
}

来自 https://github.com/near/core-contracts/blob/cd221798a77d646d5f1200910d45326d11951732/lockup/src/lib.rs#L64-L67

关于nearprotocol - 如何从地址调用不同的合约?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63879405/

相关文章:

nearprotocol - Near交易的手续费如何获取,哪些操作涉及Near金额?

nearprotocol - 跨合约调用是原子的吗?

nearprotocol - 如果稍后在智能合约中将其从状态中删除,键值写入的成本是否会降低?

nearprotocol - 在 near_sdk_rust 中对 UnorderedSet 进行分页

nearprotocol - 区 block 中的交易优先级

rust - 在近协议(protocol)合约的函数中返回多个值

nearprotocol - 如何备份NEAR智能合约数据?

javascript - close-api-js,查看合约方法调用给出 : TypeError: JSON. stringify 无法序列化循环结构

nearprotocol - 许多重试和交易在 NEAR localnet 上过期