Blockchain 使用合同A从合同B到用户地址X的补贴和转账代币
我已经部署了合同A。 现在我正在创建网关契约B,我想使用所有者地址将契约A的一些令牌发送到用户地址X。 值得一提的是,合同A所有者与合同B相同。 我做以下几点Blockchain 使用合同A从合同B到用户地址X的补贴和转账代币,blockchain,ethereum,solidity,smartcontracts,Blockchain,Ethereum,Solidity,Smartcontracts,我已经部署了合同A。 现在我正在创建网关契约B,我想使用所有者地址将契约A的一些令牌发送到用户地址X。 值得一提的是,合同A所有者与合同B相同。 我做以下几点 contract A is Ownable { // this one already deployed by owner constructor() { owner = msg.sender; // owner address is 0x123 approve(msg.sender, totalSupply); //
contract A is Ownable { // this one already deployed by owner
constructor() {
owner = msg.sender; // owner address is 0x123
approve(msg.sender, totalSupply); // let's approve all tokens for owner
}
function transferFrom(address from, address to, uint256 value) public returns (bool) {
require(value <= allowed[from][msg.sender], "Not allowed!");
// let's skip other logic
}
}
contract B is Ownable { // gateway contract will be deployed and executed by same owner
A contractA = ETC20(0x111);
address payable X = 0x333;
constructor() {
owner = msg.sender; // owner address is 0x123
}
function giveAwayTokens(uint256 value) {
contractA.transferFrom(owner, X, value);
}
}
合同A是可拥有的{//此合同已由所有者部署
构造函数(){
owner=msg.sender;//所有者地址为0x123
批准(msg.sender,totalSupply);//让我们为所有者批准所有令牌
}
函数transferFrom(地址from,地址to,uint256值)公共返回(bool){
require(值当ContractB
调用ContractA
时,ContractA
中的msg.sender
为ContractB
地址
根据代码和错误消息,所有者(0x123
)不允许ContractB
使用他们的代币
您需要将allowed[][]
的值设置为至少要发送的令牌数量
您很可能有一个approve()
函数(在令牌标准中)在链接的示例中,函数的调用者将是所有者
,支出者
将是合同B
,值
将是任何等于或高于您想要发送的令牌数量的值(注意小数点).这个例子是不完整的,因为我们不知道构造函数中的msg.sender
。@Mikkoohtama我用所有者集逻辑更新了这个例子。所以基本上两个合同所有者都是0x123地址。另外,0x123执行giveAwayTokens函数谢谢你,Petr,我会尝试一下!我已经将你的答案标记为正确答案,bec因为它一定是,它是非常合乎逻辑的!