-
Discord user DevFraccas asks: Hello everyone! I'm curious if I'm able to create a smart contract, then at a later point in time go back in and update information as the Creator. In my particular case, I'd like to create a smart contract that contains an NFT for sale, then at a later point in time go back in as the Creator and bind a specified Buyer to the contract. This code successfully creates a contract in which only the specified Buyer can make the purchase. 'reach 0.1';
'use strict';
export const main = Reach.App(() => {
const Seller = Participant('Seller', {
setSell: Fun([], Tuple(Token, UInt, UInt)),
showContract: Fun([Contract], Null),
setBuyer: Fun([], Address),
});
const Buyer = Participant('Buyer', {
getBuyInfo: Fun([Token, UInt], Null),
showBoughtAsset: Fun([Token], Null),
});
init();
// set NFT token id, nft amount, and price by Seller
Seller.only(() => {
const [ NFT, amtA, setPrice ] = declassify(interact.setSell());
});
Seller.publish(NFT, amtA, setPrice); // publish to blockchain
commit();
// Seller transfer NFTs to smart contract
Seller.pay([ [amtA, NFT ]]);
commit();
// show seller creating contract the app id (smart contract)
Seller.only(() => {
interact.showContract(getContract());
});
// seller/creator sets the buyer (bind them to the contract)
Seller.only(() => {
const BuyerAddress = declassify(interact.setBuyer());
});
Seller.publish(BuyerAddress);
// show the bound buyer the NFT asset ID and requested price
Buyer.only(() => {
check(Buyer == BuyerAddress, "Invalid Account");
interact.getBuyInfo(NFT, setPrice);
});
commit();
Buyer.pay(setPrice);
transfer(balance()).to(Seller);
transfer(balance(NFT), NFT).to(BuyerAddress);
commit();
Buyer.only(() => {
interact.showBoughtAsset(NFT);
});
exit();
}); The above example must set the Buyer during the contract creation. I'm now looking to create the contract and later bind the specified Buyer. I'm playing around with the code below, but I'm not sure if this is the best way to achieve this. 'reach 0.1';
'use strict';
export const main = Reach.App(() => {
const Creator = API('Creator', {
setBuyer: Fun([], Address)
});
const Seller = Participant('Seller', {
setSell: Fun([], Tuple(Token, UInt, UInt)),
showContract: Fun([Contract], Null),
});
const Buyer = Participant('Buyer', {
showBuyInfo: Fun([Token, UInt], Null),
showBoughtAsset: Fun([Token], Null),
});
init();
// set NFT token id, nft amount, and price by Seller
Seller.only(() => {
const [ NFT, amtA, setPrice ] = declassify(interact.setSell());
});
Seller.publish(NFT, amtA, setPrice); // publish to blockchain
commit();
// Seller transfer NFTs to smart contract
Seller.pay([ [amtA, NFT ]]);
commit();
// show seller creating contract the app id (smart contract)
Seller.only(() => {
interact.showContract(getContract());
});
Seller.publish();
commit();
const BuyerAddress = call(Creator.setBuyer).assume(() => assume(true)); // not sure about this
check(Seller == Creator, "Invalid Account");
// show the bound buyer the NFT asset ID and requested price
Buyer.only(() => {
check(Buyer == BuyerAddress, "Invalid Account");
interact.showBuyInfo(NFT, setPrice);
});
commit();
check(Buyer == BuyerAddress, "Invalid Account");
Buyer.pay(setPrice);
transfer(balance()).to(Seller);
transfer(balance(NFT), NFT).to(BuyerAddress);
commit();
Buyer.only(() => {
interact.showBoughtAsset(NFT);
});
exit();
}); I'm getting the following error in this example:
Is this the correct way to make an update in the contract? And if so, any thoughts as to why I'm getting this error? Error Info RE0085 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Notice that it's telling you the location of the error is the identifier
You've defined
The error message says that https://docs.reach.sh/rsh/step/#rsh_call You should think of APIs from the caller's perspective. Instead of this: setBuyer: Fun([], Address) I think you want to do something like this: setBuyer: Fun([Address], Null) And then you write the const [[BuyerAddress], k] = call(Creator.setBuyer);
k(null); // this is how you return the value expected by the caller of the API function; in this case just null |
Beta Was this translation helpful? Give feedback.
Notice that it's telling you the location of the error is the identifier
BuyerAddress
as it appears on this lineYou've defined
BuyerAddress
on this line:The error message says that
BuyerAddress
has aclosure
in it which can't exist at runtime.Check the docs for
call
to help understand why this is:https://docs.reach.sh/rsh/step/#rsh_call
You should think of APIs from the caller's perspective. Instead of this:
I think you want to do something like this:
And then you write the
call
…