首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用python调用with (solidity)方法

用python调用with (solidity)方法
EN

Ethereum用户
提问于 2018-06-25 12:07:50
回答 1查看 625关注 0票数 -3

我想在契约中从我的节点发送两个以太到我的invest()方法。但我不知道用蟒蛇怎么做。

稳固性:

代码语言:javascript
复制
function invest() payable { 

    value = msg.value / 1000000000000000000;
    counter += value;
    if(value >0 && value < 3){
         lastdonation = msg.sender;
        if(counter  % 5 == 0){
            winner = msg.sender;
            winnerbool =true;
            message = "congratulation you won 3 Ether";
            //if he wins he will get the 3 Ether; 
            winner.send(msg.value);

        }else{
            bank.send(msg.value);
            winnerbool= false;
            message = "No luck. Try it again";
        }
           }
        else{
           message = "Transaktion not possible. it is just possible to input 
integer ether of one or two.";
        }
    }

我已经有合同的例子了。效果很好。但是,我现在怎样才能调用我的投资()方法,它是应付的,并给合同两个乙醚?

Python:

代码语言:javascript
复制
def clean1():
    button1.config(text="Send 1 Ether")
    fContract.invest({from: "0x3eC35e7525cDd47c76da8D8BcAA945a64e55096B", 
value= "1000000000000000"})
    if fContract.functions.Winner().call():
        window.after(10, winner)
    else:
        window.after(10, lose)

button1 = Button(window, text="Send 1 Ether",bg="DodgerBlue4", fg="white", 
command=readone)
button1.grid(row=2, column=0)
button1.config(height = 4 , width = 23 )

我想做同样的东西,就像云彩正在做的一样。将2以太发送到invest()方法。

百里香薄雾

有人能帮忙吗?

EN

回答 1

Ethereum用户

发布于 2018-06-25 12:47:03

使用web3py,您可以访问契约中的函数,我认为这就是您要做的事情。从您的代码中,我得到契约实例是fcontract

你可以:

代码语言:javascript
复制
fcontract.functions.invest().transact({'from':'you account address','value': web3.toWei(2,'ether')})

注意:在执行上面的行之前,请记住解锁您的帐户。

希望这能有所帮助

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/52020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档