如何从其地址调用不同的合约?
How to call different contract from its address?
在 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);
我可以在 near 协议中这样做吗?
near 中的示例有所不同,需要提供 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,
))
第一次调用接口是(<arg_0>, <arg_1>, ..., <arg_n>, <ACCOUNT_ID>, <ATTACHED_DEPOSIT>, <ATTACHED_GAS>)
<arg_0>, <arg_1>, ..., <arg_n>
- 来自下面定义的接口的参数
<ACCOUNT_ID>
- 部署调用合约的账户
<ATTACHED_DEPOSIT>
- yocto-NEAR 中附加到呼叫的金额
<ATTACHED_GAS>
- 传递给调用的 Gas 量
它后来使用 .then
将回调附加到第一个承诺。回调只是另一个异步函数调用。
high-level接口ext_whitelist
定义如下:
#[ext_contract(ext_whitelist)]
pub trait ExtStakingPoolWhitelist {
fn is_whitelisted(&self, staking_pool_account_id: AccountId) -> bool;
}
在 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);
我可以在 near 协议中这样做吗? near 中的示例有所不同,需要提供 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,
))
第一次调用接口是(<arg_0>, <arg_1>, ..., <arg_n>, <ACCOUNT_ID>, <ATTACHED_DEPOSIT>, <ATTACHED_GAS>)
<arg_0>, <arg_1>, ..., <arg_n>
- 来自下面定义的接口的参数<ACCOUNT_ID>
- 部署调用合约的账户<ATTACHED_DEPOSIT>
- yocto-NEAR 中附加到呼叫的金额<ATTACHED_GAS>
- 传递给调用的 Gas 量
它后来使用 .then
将回调附加到第一个承诺。回调只是另一个异步函数调用。
high-level接口ext_whitelist
定义如下:
#[ext_contract(ext_whitelist)]
pub trait ExtStakingPoolWhitelist {
fn is_whitelisted(&self, staking_pool_account_id: AccountId) -> bool;
}